gpt4 book ai didi

opencv - opencv上的直方图

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:47 24 4
gpt4 key购买 nike

嘿,我试图制作一个显示帧减法的直方图,代码正在运行,但我得到灰色窗口但没有结果。命令窗口上的消息是:编译器没有对齐堆栈变量。 Libavcodec 被错误编译并且可能非常缓慢或崩溃。这不是 libavcodec 中的错误,但在编译器中。您可以尝试使用 gcc >= 4.2 重新编译。不要向 FFmpeg 开发人员报告崩溃。OpenCV 错误:断言失败 (images[j].channels() == 1) 在未知函数中,文件........\ocv\opencv\src\cv\cvhistogram.cpp,第137行

这是有人有想法的代码吗?感谢您的帮助......

int main()  
{


int key = 0;




CvCapture* capture = cvCaptureFromAVI( "macroblock.mpg" );
IplImage* frame = cvQueryFrame( capture );
IplImage* currframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
IplImage* destframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
IplImage* imgHistogram = 0;
CvHistogram* hist;



if ( !capture )

{
fprintf( stderr, "Cannot open AVI!\n" );
return 1;
}

int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );

cvNamedWindow( "dest", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "imgHistogram", CV_WINDOW_AUTOSIZE );

while( key != 'x' )
{
frame = cvQueryFrame( capture );
currframe = cvCloneImage( frame );
frame = cvQueryFrame( capture );



cvSub(frame,currframe,destframe);

int bins = 256;
int hsize[] = {bins};
float max_value = 0, min_value = 0;
float value;
int normalized;
float xranges[] = {0, 256};
float* ranges[] = {xranges};
IplImage* planes[] = {destframe};

hist = cvCreateHist(1, hsize, CV_HIST_ARRAY, ranges,1);
cvCalcHist(planes, hist, 0, NULL);
cvGetMinMaxHistValue(hist, &min_value, &max_value);
// printf("Minimum Histogram Value: %f, Maximum Histogram Value: %f\n", min_value, max_value);
imgHistogram = cvCreateImage(cvSize(bins, 50),IPL_DEPTH_8U,3);
cvRectangle(imgHistogram, cvPoint(0,0), cvPoint(256,50), CV_RGB(255,255,255),-1);

for(int i=0; i < bins; i++){
value = cvQueryHistValue_1D(hist, i);
normalized = cvRound(value*50/max_value);
cvLine(imgHistogram,cvPoint(i,50), cvPoint(i,50-normalized), CV_RGB(0,0,0));

}



if(key==27 )break;
cvShowImage( "dest",destframe);
cvShowImage( "imgHistogram",imgHistogram);

key = cvWaitKey( 1000 / 10 );
}
cvDestroyWindow( "dest" );
cvReleaseCapture( &capture );
return 0;
}

最佳答案

由于您尝试显示一维直方图,因此直方图平面需要为灰度。因此,您需要先将生成的图像从 cvSub() 转换为灰度。尝试

IplImage *gray = NULL;
gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);

while(key != 'x') {
...
cvSub(frame, currframe, destframe);
cvCvtColor(destframe, gray, CV_BGR2GRAY);
...
IplImage* planes[] = {gray};
..
}

让我知道它是否适合您。

关于opencv - opencv上的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com