Should Sony PS3 camera work with VideoCapture? [closed]
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?
flaw in your code, put
inside your loop ! (else you only read a single image, if at all ....)"
((some webcams also need a "warmup", and deliver black frames initially))
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 whyMat 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 lineseems to create a window. Does it give the window the name "Webcam"?
yes, imshow() will create a window, if none of that name exists. the namedWindow() call is to specify flags
Thank you, the problen is solved