Hey guys,
I wanted to write a program which takes N live webcam images, calculates an averaged-image out of it and saves the average image as a jpg. I'm passing the filename and the number N of images to be averaged as parameters.
First I thought everything is working fine with my code, but sometimes the program crashes during runtime (I'm calling the exe via LabVIEW). I'm not changing N, only the filename-number is incremented by 1 for each call, so I don't think that's the issue. It crashes about 1 time in 25 calls but it's nor really reproducible when. With crashing I mean the window freezes, and is greyed out by Windows and I get the promt that the program isn't responding.
Here is my code:
#include
#include
#include "opencv2/highgui/highgui.hpp"
#include
#include
#include
#include
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
string outputfilename;
int NMean; // number of images to take mean values of
if (argc == 2)
{
outputfilename = argv[1];
NMean = 100;
}
else if(argc > 2)
{
outputfilename = argv[1];
istringstream ss(argv[2]);
ss >> NMean;
}
else
{
outputfilename = "newframe.jpg";
NMean = 100;
}
VideoCapture cap(0);
if (!cap.isOpened())
{
cout << "Cannot open the video cam" << endl;
return -1;
}
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1024);
namedWindow("WebcamImage",CV_WINDOW_AUTOSIZE);
Mat frame;
Mat meanImage(1024, 1280, CV_32FC3, cv::Scalar(0));
for (int i=0; i
↧