opencv

来源:互联网 发布:合肥市行知学校地址 编辑:程序博客网 时间:2024/06/02 13:02

矩阵操作

#include "cv.h"
#include "highgui.h"
int main(int argc ,char **argv)
{
double a[]={1,2,3,4,
5,6,7,8,
9,10,11,12};
CvMat Ma = cvMat(3,4,CV_64FC1,a);
int n = Ma.cols;
float *data = Ma.data.fl;
for(int i=0;i<Ma.rows;++i)
for(int j=0;j<Ma.cols;++j)
printf("%f ",data[i*n+j] );


return 0;
}


#include "cv.h"
#include "highgui.h"
void mouseHandler(int event, int x, int y, int flags, void *param)
{
switch(event)
{
case CV_EVENT_LBUTTONDOWN:
if(flags & CV_EVENT_FLAG_CTRLKEY)
printf("Left button down with CTRL pressed\n");
break;
case CV_EVENT_LBUTTONUP:
printf("Left button up\n");
break;
}
}

int main(int argc ,char **argv)
{
// CvCapture *capture = cvCaptureFromCAM(0);
IplImage *laplace = 0;
IplImage *colorlaplace = 0;
IplImage *planes[3] = {0,0,0};
CvCapture *capture = 0;
if( argc==1 || (argc==2 && strlen(argv[1])==1 && isdigit(argv[1][0])) )
capture = cvCaptureFromCAM(argc==2?argv[1][0]-'0':0);
else if(argc==2)
capture = cvCaptureFromAVI(argv[1]);
if(!capture)
{
fprintf(stderr,"Could not initialize capturing...\n");
return -1;


}
cvNamedWindow("Laplacian", 0);
for(;;)
{
IplImage *frame = 0;
int i;
frame = cvQueryFrame(capture);
if(!frame)
break;
if(!laplace)
{
for(i=0; i<3; ++i)
{
planes[i] = cvCreateImage(cvSize(frame->width,frame->height),8,1);
}
laplace = cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_16S,1);
colorlaplace = cvCreateImage(cvSize(frame->width,frame->height),8,3);
}
cvCvtPixToPlane(frame, planes[0],planes[1], planes[2],0);
for(i=0;i<3;++i)
{
cvLaplace(planes[i],laplace,3);
cvConvertScaleAbs(laplace,planes[i],1,0);
}
cvCvtPlaneToPix(planes[0],planes[1],planes[2],0,colorlaplace);
colorlaplace->origin = frame->origin;


cvShowImage("Laplacian",colorlaplace);


if(cvWaitKey(10)>=0)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Laplacian");


return 0;
}