Ask Your Question

ColinS747's profile - activity

2019-05-14 23:53:32 -0500 received badge  Famous Question (source)
2018-02-24 12:13:02 -0500 received badge  Notable Question (source)
2017-11-02 12:36:09 -0500 received badge  Popular Question (source)
2015-10-28 06:57:54 -0500 received badge  Enthusiast
2015-10-13 06:37:10 -0500 received badge  Editor (source)
2015-10-13 06:36:55 -0500 commented answer OpenCV failing to open camera

I should also point out that this program previously worked as expected on a desktop PC running debian based linux. I have only had these problems when trying to run the program on a macbook running OSX.

2015-10-13 06:33:38 -0500 commented answer OpenCV failing to open camera

I only have code to access the camera in a one of the two threads. These two programs are never ran at the same time.

2015-10-13 06:08:54 -0500 commented answer OpenCV failing to open camera

I'm not sure what you mean, could you elaborate?

2015-10-13 05:21:28 -0500 commented answer OpenCV failing to open camera

This doesn't solve my problem though. As I said my code was working fine when it was all included in a single thread but fails to open the camera when it is applied in a multi-threaded implementation. I'm looking to know why it fails in this case and how to fix it.

2015-10-13 04:36:11 -0500 commented answer OpenCV failing to open camera

The code you provided works fine. I only had to add std:: to the cerr and endl.

2015-10-08 03:59:15 -0500 asked a question OpenCV failing to open camera

I have an OpenCV program that is supposed to use a webcam (in this case the built in laptop camera). The program compiles fine without error but when I run it the program seems to hang on the line:

img_scene = cvCaptureFromCAM(0);

I have a different program that access the camera in the same fashion so I don't understand as to why this program seems to be having trouble.

Full capture code from non-working program:

Mat captureThread() {
  if(captureOpen == false){
    img_scene = cvCaptureFromCAM(0);
    cvSetCaptureProperty(img_scene, CV_CAP_PROP_FRAME_WIDTH, 640);
    cvSetCaptureProperty(img_scene, CV_CAP_PROP_FRAME_HEIGHT, 480);
  }
  while(1) {
    image = cvQueryFrame(img_scene);
    if(image.empty()) {
      continue;
    }
    cvtColor(image, gray, CV_BGR2GRAY);
    return gray;
  }
}

This is the code that is being used in a different program that is working as expected:

  img_scene = cvCaptureFromCAM(0);
  cvSetCaptureProperty(img_scene, CV_CAP_PROP_FRAME_WIDTH, 640);
  cvSetCaptureProperty(img_scene, CV_CAP_PROP_FRAME_HEIGHT, 480);
  while(1) {
    imageFrame = cvQueryFrame(img_scene);
    if(imageFrame.empty()) {
      continue;
      cout << "image frame is empty" << endl;
    }
    cvtColor(imageFrame, gray, CV_BGR2GRAY);

What is causing the non-working program to have trouble access the camera? I have also tried plugging in a USB camera and setting cvCaptureFromCam(-1) but it does not work either.

EDIT: The non-working program uses multiple threads whereas the working program does not.

I should also point out that this program previously worked as expected on a desktop PC running debian based linux. I have only had these problems when trying to run the program on a macbook running OSX.