Ask Your Question

interference's profile - activity

2015-09-10 07:20:05 -0600 received badge  Editor (source)
2015-09-10 07:19:11 -0600 asked a question webcam image overexposed on second program call

Hey guys, I have some issues with my webcam as it doesn't show the rightly exposed image in opencv. When I'm using the provided webcam-software or skype I get the same image. However using opencv the image is different as it's overexposed. I noticed that when I launch my opencv application (which only shows the current images) after aquiring an image with a different software, everything is good. But restarting my program gives me the overexposed images again. I also tried to change the exposure via CV_CAP_PROP_EXPOSURE in cap.set but that didn't work either. So what could be the issue, did you encounter such a problem yet? It seems like opening my program changes some (internal?) webcam settings on closing, such that the image is overexposed when I'm calling it again. Thanks a lot and best regards!

2015-08-31 08:11:32 -0600 received badge  Teacher (source)
2015-08-25 02:52:56 -0600 received badge  Self-Learner (source)
2015-08-25 02:12:04 -0600 answered a question computing average image of N webcam images crashes sometimes

Hey, thanks for your answers and sorry for my late reply! I added your hint if(frame.empty()){ continue; } but it didnt't help. I noticed that the program always crashes on cap.release(); Recently I found out that there was running another service on my PC called "arcsoft connect daemon" which came somehow installed with my webcam. After turning it off there are no problems anymore. I was able to call the program about 16.000 times without an error ;)

2015-08-11 03:54:29 -0600 asked a question computing average image of N webcam images crashes sometimes

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 <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

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<NMean; i++)
    {

        bool bSuccess = cap.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }

        imshow("WebcamImage", frame);
        accumulate(frame, meanImage);

       if (waitKey(30) == 27)
       {
            cout << "esc key is pressed by user" << endl;
            break;
       }
    }

    meanImage = meanImage / NMean;
    meanImage.convertTo(meanImage,CV_8UC3);
    imwrite(outputfilename.c_str(),meanImage);

    cap.release();
    destroyWindow("WebcamImage");

    return 0;

}

I noticed that during a crash the averaged image is still saved. So the error must occur after the last imwrite (I also tried to put destroyWindow in front of break; but it didn't help).

What could be the issue? Thanks a lot and best regards!