如何知道帧或图像的大小
How to know the size of a frame or image
这对大多数人来说似乎微不足道,但我在确定视频帧的确切大小(即确切宽度和高度)时遇到了问题。我使用了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;
}
尝试以下代码:)关键是cvGetSize函数和CvSize结构的使用。
#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);
CvSize dim = cvGetSize(gray_frame);
cout <<" dimensions:: height:" << dim.height<<" width:"<< dim.width<< 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;
}
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 叮当不知道PTRDIFF_MAX?
- 如何在不知道向量大小的情况下输入向量内部的向量?
- 平均图像时图像损坏
- OpenGL如何知道将哪个图像单元附加到制服上?
- 让主程序知道资源在哪里(图像、数据等)
- 从内存中读取图像,知道指向内存的指针.VC++
- 如何知道帧或图像的大小
- 我如何才能知道OpenCV中的图像是否为RGB
- 不知道如何保存 BMP 图像
- 我的加载图像不起作用 - 我需要知道为什么
- 我怎么知道图像扫描的进度
- 重新缩放图像只需知道保留纵横比的比例因子即可