Should Sony PS3 camera work with VideoCapture? [closed]

asked 2020-03-25 13:19:44 -0500

andrei186 gravatar image

Trying to combine Ubuntu 18, OpenCV 3.4.10 and Sony PS3 camera. Use the standard sample code found on opencv.org:

#include "opencv2/opencv.hpp"
#include "iostream"

int main(int, char**) {
cv::VideoCapture camera(0);
if (!camera.isOpened()) {
    std::cerr << "ERROR: Could not open camera" << std::endl;
    return 1;   }
cv::namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
cv::Mat frame;
camera >> frame;
while (1) {
    cv::imshow("Webcam", frame);
    if (cv::waitKey(10) >= 0)
        break;
}
return 0;

}

Compiles without errors, Executes without errors too. Yet shows nothing as if the code is not supposed to display anything. With the camera unplugged returns "ERROR: Could not open camera".

In dev the camera shows as video0.

With Cheese it works fine. On Raspberry Pi similar test code in Python works fine with PS3 - detected it immediately.

I have five other cameras of different models, none works with this code: three behave same as PS3, others complain about pixel format not supported. This might mean that the problem is not necessary with the PS3 driver.

Someone suggested to install Video4Linux - made no difference.

What else could be done? Or perhaps something wrong is with the code?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by andrei186
close date 2020-03-27 04:46:03.558152

Comments

flaw in your code, put

camera >> frame;
if (frame.empty()) break;

inside your loop ! (else you only read a single image, if at all ....)"

((some webcams also need a "warmup", and deliver black frames initially))

berak gravatar imageberak ( 2020-03-25 13:34:50 -0500 )edit

Thank you. This half-worked: it shows just a single frame. But it set a direction to dig. The code I use has more flaws. cv::Mat frame should also be inside loop, thought I do not understand why Mat frame needs to be created for every frame and why it cannot be created outside the loop and then re-used.

The purpose of cv::namedWindow("Webcam", CV_WINDOW_AUTOSIZE) is unclear for the code works without it The line

 cv::imshow("Webcam", frame)

seems to create a window. Does it give the window the name "Webcam"?

andrei186 gravatar imageandrei186 ( 2020-03-26 12:05:56 -0500 )edit

yes, imshow() will create a window, if none of that name exists. the namedWindow() call is to specify flags

berak gravatar imageberak ( 2020-03-27 01:53:11 -0500 )edit

Thank you, the problen is solved

andrei186 gravatar imageandrei186 ( 2020-03-27 04:45:29 -0500 )edit