- Working on a Raspberry Pi 4B
- Raspberry Pi OS
- Raspberry Pi camera module 3
- Camera works fine using commandline rpicam-vid
I Have not enabled legacy camera in raspi-config since that is no longer an option
Video capture works fine using files, but i cannot get a live acces to a camera.
I have tried index -1, 0 and 1 for the devices but only ‘0’ responds.
I have tried most of the APIs but only V4L and GStreamer results in anything.
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
#include "vision.h"
int main(int argc, char** argv )
{
cv::Mat frame;
cv::VideoCapture vid;
printf("CAP_V4L : ");
vid.open(0,cv::CAP_V4L);
cv::waitKey(2000);
if(!vid.isOpened()){
printf("Cam not opened\n");
}else{
printf("Cam opened!\n");
double dWidth = vid.get(cv::CAP_PROP_FRAME_WIDTH);
double dHeight = vid.get(cv::CAP_PROP_FRAME_HEIGHT);
printf("Frame size : %f x %f\n",dWidth , dHeight);
if(vid.grab()){// used to be if(vid.read(frame)){
//imshow("LIVE!", frame);
printf("grabbed\n");
cv::waitKey(0);
}else{
vid.release();
printf("no frame\n");
}
}
std::cout << "CAP_GSTREAMER : " << std::endl;
vid.open(0,cv::CAP_GSTREAMER);
std::cout << "DOES NOT REACH HERE : " << std::endl;
if(!vid.isOpened()){
printf("Cam not opened\n");
}else{
printf("Cam opened!\n");
vid.read(frame);
imshow("LIVE!", frame);
cv::waitKey(0);
}
return 0;
}
This code response:
CAP_V4L : Cam opened!
Frame size : 640.000000 x 480.000000
[ WARN:0@10.060] global ./modules/videoio/src/cap_v4l.cpp (1013) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
no frame
CAP_GSTREAMER :
Then does nothing until I ctrl+C