我无法理解为什么我的程序无法在我的电脑上运行而在学校的电脑上运行正常!也许这是配置上的问题。我使用Ubuntu 9.10和opencv 2.2的最后一个版本
以下是代码:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
int main (int argc, char *argv[])
{
double a[9]={1,0,-1,2,0,-2,1,0,-1};
double b[9]={1,2,1,0,0,0,-1,-2,-1};
IplImage* img=cvLoadImage(argv[1], 0);
if(!img){
printf("could not load image file: %s\n",argv[1]);
exit(0);
}
IplImage* dst=cvCreateImage(cvGetSize(img),IPL_DEPTH_64F,1);
IplImage* dst1=cvCreateImage(cvGetSize(img),IPL_DEPTH_64F,1);
IplImage* dst2=cvCreateImage(cvGetSize(img),IPL_DEPTH_64F,1);
IplImage* dst_f=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
CvMat k1 = cvMat(3,3,CV_64FC1,a);
CvMat k2 = cvMat(3,3,CV_64FC1,b);
cvFilter2D( img ,dst1, &k1,cvPoint(-1,-1));
cvFilter2D( img ,dst2, &k2,cvPoint(-1,-1));
cvPow(dst1, dst1, 2.0);
cvPow(dst2, dst2, 2.0);
cvAdd(dst1, dst2, dst, NULL);
cvPow(dst, dst, 0.5);
cvConvertImage(dst,dst_f,CV_CVTIMG_FLIP);
cvThreshold(dst_f,dst_f,127,255,CV_THRESH_BINARY);
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvShowImage("mainWin",img);
cvNamedWindow("Sobel", CV_WINDOW_AUTOSIZE);
cvShowImage("Sobel",dst_f);
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&dst_f);
return 0;
}
这是终端在运行时返回的内容
OpenCV错误:输入格式 参数在函数中不匹配() cvFilter2D,cvfilter.cpp(2617) 终止应用程序...被叫 来自cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 应用程序......来自 cvUnregisterType, cxpersistence.cpp(4933)终止 申请......
请帮我理解这个问题。
答案 0 :(得分:0)
您的错误是错误的,您需要使用CvMat变量来存储矩阵以存储过滤器并将其应用到带有cvFilter 2D的图像中。
我给你2个示例代码来理解这个程序。
创建并初始化矩阵。
double a[] = { 1, 2, 3, 4
5, 6, 7, 8,
9, 10, 11, 12 };
double b[] = { 1, 5, 9,
2, 6, 10,
3, 7, 11,
4, 8, 12 };
double c[9];
CvMat Ma, Mb, Mc ;
cvInitMatHeader( &Ma, 3, 4, CV_64FC1, a );
cvInitMatHeader( &Mb, 4, 3, CV_64FC1, b );
cvInitMatHeader( &Mc, 3, 3, CV_64FC1, c );
cvMatMulAdd( &Ma, &Mb, 0, &Mc );
// c array now contains product of a(3x4) and b(4x3) matrices
答案 1 :(得分:0)
使用矩阵初始化的另一个选项进行高通滤波的示例
int main()
{ CvMat * kernel = 0; IplImage * src = cvLoadImage(“chica.jpg”); IplImage * dst = cvCreateImage(cvGetSize(src),32,3);
kernel = cvCreateMat(3, 3,CV_32FC1);
cvSet2D( kernel, 0, 0, cvRealScalar(0));
cvSet2D( kernel, 0, 1, cvRealScalar(-1));
cvSet2D( kernel, 0, 2, cvRealScalar(0));
cvSet2D( kernel, 1, 0, cvRealScalar(-1));
cvSet2D( kernel, 1, 1, cvRealScalar(5));
cvSet2D( kernel, 1, 2, cvRealScalar(-1));
cvSet2D( kernel, 2, 0, cvRealScalar(0));
cvSet2D( kernel, 2, 1, cvRealScalar(-1));
cvSet2D( kernel, 2, 2, cvRealScalar(0));
// Matriz utilizada para el filtrado paso alto
// 0 -1 0
// -1 5 -1
// 0 -1 0
cvFilter2D(src, dst, kernel, cvPoint(-1,-1));
cvNamedWindow("Image Original",1);
cvShowImage("Image Original",src);
cvNamedWindow("Image Filtrada",1);
cvShowImage("Image Filtrada",src);
cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&dst);
cvDestroyWindow("Image Original");
cvDestroyWindow("Image Filtrada");
// release the image
return 0;
}