cv :: add在openCV中不起作用 [英] cv::add doesn't work in openCV
本文介绍了cv :: add在openCV中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试建立10帧的平均值,所以我尝试:
I' try to build the mean value of 10 frames so I tried :
.....
cv::Mat frame,outf,resultframe1, resultframe2;
VideoCapture cap(1);
cap>> frame;
resultframe1 = Mat::zeros(frame.rows,frame.cols,CV_32F);
resultframe2 = Mat::zeros(frame.rows,frame.cols,CV_32F);
while(waitKey(0) != 27}{
cap>> frame;
if ( waitKey(1) = 'm'){
for ( int j = 0 ; j <= 10 ; j++){
cv::add(frame,resultframe1,resultframe2);// here crashes the program ?????
....
}
}
我解决了。
提前感谢
any Idea how can I solve that. thanks in advance
推荐答案
当你有操作符时,不需要显式地调用add函数可以使用OpenCV C ++接口。这是如何平均指定的帧数。
There is no need to call the add function explicitly when you have operators available in OpenCV C++ interface. Here is how you can average the specified number of frames.
void main()
{
cv::VideoCapture cap(-1);
if(!cap.isOpened())
{
cout<<"Capture Not Opened"<<endl; return;
}
//Number of frames to take average of
const int count = 10;
const int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
const int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
cv::Mat frame, frame32f;
cv::Mat resultframe = cv::Mat::zeros(height,width,CV_32FC3);
for(int i=0; i<count; i++)
{
cap>>frame;
if(frame.empty())
{
cout<<"Capture Finished"<<endl; break;
}
//Convert the input frame to float, without any scaling
frame.convertTo(frame32f,CV_32FC3);
//Add the captured image to the result.
resultframe += frame32f;
}
//Average the frame values.
resultframe *= (1.0/count);
/*
* Result frame is of float data type
* Scale the values from 0.0 to 1.0 to visualize the image.
*/
resultframe /= 255.0f;
cv::imshow("Average",resultframe);
cv::waitKey();
}
在创建矩阵时始终指定完整类型,例如 CV_32FC3
,而不是只有 CV_32F
。
Always specify complete type when creating matrices, like CV_32FC3
instead of only CV_32F
.
这篇关于cv :: add在openCV中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文