OpenCV

Z Varhoo
(Rozdíly mezi verzemi)
Přejít na: navigace, hledání
(Nová stránka: Při překladu je nutné použít v makefilu `pkg-config opencv --libs` `pkg-config opencv --cflags --libs` Do hlaviček je pak potřeba knihovny #include <cv.h> #include <highg...)
 
m (Vytvoření výřezu obrázku)
 
(Nejsou zobrazeny 3 mezilehlé verze od 2 uživatelů.)
Řádka 1: Řádka 1:
 
 
Při překladu je nutné použít v makefilu
 
Při překladu je nutné použít v makefilu
 
`pkg-config opencv --libs`
 
`pkg-config opencv --libs`
Řádka 6: Řádka 5:
   
 
Do hlaviček je pak potřeba knihovny
 
Do hlaviček je pak potřeba knihovny
#include <cv.h>
+
#include <cv.h>
#include <highgui.h>
+
#include <highgui.h>
  +
  +
Vytvoření obrázku
  +
  +
IplImage * img = cvCreateImage(cvSize(640480),IPL_DEPTH_8U,1);
  +
  +
  +
==Vytvoření výřezu obrázku==
  +
  +
IplImage* get_subimage(IplImage* src, CvRect interest_rect)
  +
{
  +
int width, height;
  +
  +
//kontrola delky vyrezu
  +
if(src->width < interest_rect.width + interest_rect.x) {
  +
width = src->width - interest_rect.x;
  +
} else {
  +
width = interest_rect.width;
  +
}
  +
  +
if(src->height < interest_rect.height + interest_rect.y) {
  +
height = src->height - interest_rect.y;
  +
} else {
  +
height = interest_rect.height;
  +
}
  +
  +
/* Create a new image header */
  +
IplImage* subimg = cvCreateImageHeader(
  +
cvSize(
  +
width, height
  +
),
  +
src->depth,
  +
src->nChannels
  +
);
  +
  +
/* Mimic the input image */
  +
subimg->origin = src->origin;
  +
subimg->widthStep = src->widthStep;
  +
  +
/* Points to the interest rectangle */
  +
subimg->imageData = src->imageData + src->widthStep * interest_rect.y +
  +
interest_rect.x * src->nChannels;
  +
  +
/* And we've got a subimage */
  +
return subimg;
  +
}

Aktuální verze z 19. 5. 2011, 01:32

Při překladu je nutné použít v makefilu

`pkg-config opencv --libs`
`pkg-config opencv --cflags --libs`


Do hlaviček je pak potřeba knihovny

#include <cv.h>
#include <highgui.h>

Vytvoření obrázku

IplImage * img = cvCreateImage(cvSize(640480),IPL_DEPTH_8U,1);


[editovat] Vytvoření výřezu obrázku

IplImage* get_subimage(IplImage* src, CvRect interest_rect)
{
 int width, height;

 //kontrola delky vyrezu
 if(src->width < interest_rect.width + interest_rect.x) {
		width =  src->width - interest_rect.x;
 } else {
     width = interest_rect.width;
 }
 
 if(src->height < interest_rect.height + interest_rect.y) {
      height =  src->height - interest_rect.y;
 } else {
      height = interest_rect.height;
 }

 /* Create a new image header */
 IplImage* subimg = cvCreateImageHeader(
   cvSize(
		width, height
   ),
   src->depth,
   src->nChannels
 );

 /* Mimic the input image */
 subimg->origin    = src->origin;
 subimg->widthStep = src->widthStep;

 /* Points to the interest rectangle */
 subimg->imageData = src->imageData + src->widthStep * interest_rect.y +
                     interest_rect.x * src->nChannels;

 /* And we've got a subimage */
 return subimg;
}
Osobní nástroje