Raspberry Pi 4 streaming OpenCV frames through RTSP/RTMP - opencv

I'm using a RPI 4 with Pi Camera and OpenCV to get the video stream from the Pi camera, and detect a face, then tracking it using servo motors.
If I want to see the feed, I can use cv2.imshow("",frame) with the frame read from the stream.
I'm looking for a way to output the frames to be used as a webcam. For example using rtsp to make the RPI an IP camera, then using VLC to get the feed.
Problem is, I can't find a way to implement in my code to actually stream the frames. I tried using ffmpeg, but the rtsp server part is missing, I need to somehow start in my code, maybe with a package of somekind.
If anyone has a better suggestion to use the RPI with my code as a webcam, I would be happy to hear.
Thanks

Related

integrating OpenGL with webcam in python language

how to integrate webcam texture with the OpenGL in python language . i didnt get any example on internet
plzz answer
As always in Programming, I would start by splitting the problem into smaller Problems:
Getting the webcam feed (if you do not have it already)
For getting webcam data I would start here: How do I access my webcam in Python? (Basically get the webcam feed using OpenCV or GStreamer)
Make sure the data is in an 1D array in RGB color format
Once you have video feed from the camera, it should be fairly straight forward to take the newest frame and upload it to a OpenGL texture using GL.glTexImage2D. (example)
This is assuming you to be familiar with OpenGL already, if not, you can try to follow some OpenGL tutorials until you feel comfortable enough for step 3.

Reading video from OpenMV H7 camera over ttyACM0 port using c++ code

I have an OpenMV H7 camera who's output I need to read into OpenCV. Now, the serial output is ttyACM0 where I am able to stream image frames. How can I read these frames in c++ code? I cannot use cv::VideoCapture() as the camera is not recognized as a video device. Serial libraries for C++ that I've found so far are quite messy. I am able to do this on python using serial library. Any help in reading into c++ would be valuable.

usb webcam runs slowly on raspberry pi with opencv

I have some code that I have adapted to run on a headless Rpi using a usb webcam, it is running a bit slow, so my questions are:
If I were to use the GPI pins with a dedicated webcam would that be faster?
Is there any way to speed up my code for Rpi?
Where can I get a Rpi webcam?
My code is here, I struggle to paste inline so its a link
For your question about where to get a Pi camera, a new camera has recently been release. I don't know about speeding up you code, but you might want to overclock your Pi. Good luck,
Like Quentin suggested, a dedicated Camera (in our case, Rpi camera link : http://www.raspberrypi.org/camera) should work much faster than USB webcams as it is known to use GPU for encoding / decoding process instead of using CPU.
(Source : http://www.raspberrypi.org/phpBB3/viewtopic.php?t=55798)
You can try reducing width and height of the frame for better performance in terms of speed.
Also you're using Iplimage* which is no longer supported in new OpenCV versions and replaced by cvMat.
(source: Difference between cvMat, Mat and IpImage)
Hope it helps.

Use webcam with opencv without x

I want to use opencv with a webcam on a headless system, no ui/x, on a raspberry pi (Raspbian)
Is this feasible? Has it been done?
Actually there is no X strictly needed to get and process images/video in opencv taken from webcam/raspicam.
You need to acquire the img raw data stream from cam matrix interface and then do what you whant in SDL/OGL etc
See
here and
here and
here faq

2 usb cameras not working with opencv

I'm working on a project of computer vision and I need to use two cameras using opencv library. I tried this code but with two webcams from USB port it doesn't work while it works if I use one usb camera and the camera of my pc.
CvCapture* capture[2];
capture[0] = cvCreateCameraCapture(0);
capture[1] = cvCreateCameraCapture(1);
if(!capture[0] && !capture[1])
printf("Webcam error\n");
I'm working on windows 7 on an acer aspire 5742g. Is it a problem of the bus of my computer? The cameras are 2 Philips SPZ2000.
I tried also to work on the pictures taken by the one of them and from the camera on my pc and when I use the code for calibration and rectification found on the book "Learning opencv" of Bradsky I get a bad result. Can somebody help me?
Thank you in advance,
Sara
The typical reason for 2+ USB cameras to not work together (still they might be working fine separately) is that USB bandwidth is insufficient for them both to run simultaneously. There is a bandwidth limit, which is rather low: The maximum throughput of an isochronous pipe (which is usually used for video) is 24MB/s.
More on this issue:
Implications of using many USB web cameras
How many USB cameras can be accessed by one PC
Not able to capture video using 2 webcamera simulteneously
Two webcams on one usb hub - bandwidth issues

Resources