比较网络摄像头帧时,cvNorm() 始终返回 0
我正在尝试编写一个程序,打印出从网络摄像头捕获的两帧(相距 30 帧)之间的范数,但 cvNorm 始终返回 0。我做错了什么?代码如下:
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *frame = 0;
int key = 0;
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
/* always check */
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
IplImage *image;
IplImage pastImage;
for(int i = 0; key != 'q'; i++ ) {
image = cvQueryFrame(capture);
这是检查发生的地方:
if(!(i %30)){
if(i){
cout<<cvNorm(&pastImage,image)<<endl;
}
memcpy(&pastImage,image, sizeof(IplImage));
}
frame = image;
/* always check */
if( !frame ) break;
/* display current frame */
cvShowImage( "result", frame );
/* exit if user press 'q' */
key = cvWaitKey( 1 );
}
/* free memory */
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
I'm trying to write a program that prints out the norm between two frames (30 frames apart) captured from a webcam, but cvNorm always returns 0. What am I doing wrong? Code follows:
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *frame = 0;
int key = 0;
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
/* always check */
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
IplImage *image;
IplImage pastImage;
for(int i = 0; key != 'q'; i++ ) {
image = cvQueryFrame(capture);
Here's where the checking occurs:
if(!(i %30)){
if(i){
cout<<cvNorm(&pastImage,image)<<endl;
}
memcpy(&pastImage,image, sizeof(IplImage));
}
frame = image;
/* always check */
if( !frame ) break;
/* display current frame */
cvShowImage( "result", frame );
/* exit if user press 'q' */
key = cvWaitKey( 1 );
}
/* free memory */
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
memcpy 图像对象不会复制图像。它复制图像元数据。元数据指向实际的图像像素。 OpenCV中应该有图像复制功能。就这么称呼吧
这是有关该主题的教程: http://nashruddin.com/ opencv-examples-for-operation-on-images.html/4
memcpy'ing the image object does not copy the image. It copies the image metadata. The metadata points to the actual image pixels. There should be an image copy function in OpenCV. Call that.
Here's a tutorial on the subject: http://nashruddin.com/opencv-examples-for-operation-on-images.html/4