对于大多数人来说,这似乎微不足道,但我在确定确切大小时遇到了问题,即我的视频帧的确切宽度和高度。我使用了 cvGetSize,但我可能编码不准确,因为我遇到了错误。是否可以输出我在下面的代码中包含的帧的宽度和高度值?如果有人能就此提出建议,我将不胜感激。
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main( int argc, char* argv ) {
CvCapture *capture = NULL;
capture = cvCaptureFromAVI("C:\\walking\\lady walking.avi");
if(!capture){
return -1;
}
IplImage* color_frame = NULL;
IplImage* gray_frame = NULL ;
int thresh_frame = 17;
int frameCount=0;//Counts every 5 frames
cvNamedWindow( "contours", CV_WINDOW_AUTOSIZE );
while(1) {
color_frame = cvQueryFrame( capture );//Grabs the frame from a file
if( !color_frame ) break;
gray_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), color_frame->depth, 1);
if( !color_frame ) break;// If the frame does not exist, quit the loop
frameCount++;
if(frameCount==5)
{
cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
cvThreshold(gray_frame, gray_frame, thresh_frame, 255, CV_THRESH_TOZERO_INV);
cvGetSize(gray_frame);
int w;
int h;
cvSize(w,h);
cout <<" dimensions " << cvSize(w, h) << endl;
cvShowImage("contours", gray_frame);
frameCount=0;
}
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseImage(&color_frame);
cvReleaseImage(&gray_frame);
cvReleaseCapture( &capture );
cvDestroyWindow( "contours" );
return 0;
}