opencvsharp icon indicating copy to clipboard operation
opencvsharp copied to clipboard

Videocapture does not work with rtsp

Open NarwhalRoger opened this issue 2 years ago • 8 comments

Summary of your issue

Hi, I am new to OpenCvSharp and having a hard time understanding what I am doing wrong. My problem is the Cv2.VideoCapture method. When pass as a parameter "0" to connect to my laptop camera it works fine, however when I pass the rtsp address of my external surveillance camera it returns empty matrix. I have researched the topic and I think the issue is in GSTREAM setting being turned off. I tried to set it on, but ended up only corrupting core files of my PC. I would be very grateful if someone could explain me how to fix this problem as detailed as possible.

Environment

Windows 10 Visual Studio 2022 Console app with .NET OpenCvSharp4

Example code:


private static string camera = "rtsp://login:[email protected]:554/11"

.......

var cap = new VideoCapture(@camera);
Mat frame = new Mat();
cap.Read(frame);
Console.WriteLine(frame.Empty());
Cv2.ImShow("frame", frame);
Cv2.WaitKey();

Output:

True (means matrix is empty)
Then error, smth like: "Mat.height <= 0, Mat.width <= 0". Basically means matrix is empty

What did you intend to be?

I want it to be able to connect and stream from camera using the rtsp address as input for the VideoCapture method.

NarwhalRoger avatar Jul 11 '22 17:07 NarwhalRoger

As a sidenote: I have also tried the address without "@", and other ways like rtmp and http protocols. Doesn't work.

NarwhalRoger avatar Jul 11 '22 17:07 NarwhalRoger

Could be a stupid test but did you try to watch your camera url in VLC ?

Moreno-Borsalino avatar Jul 12 '22 17:07 Moreno-Borsalino

Hi guys. I have same issue cannot share stream we use in compnay, but can some please try to play this stream (and yes it does play in VLC). rtsp://demo:[email protected]:5541/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast

Davidkulpe avatar Jul 18 '22 21:07 Davidkulpe

@Davidkulpe Hi, I don't know what caused this problem for me, but I tried downgrading my Visual Studio from 2022 to 2019 and it started working. Also I only added one OpenCvSharp Nuget package, the OpenCvSharp.Windows or smth like that.

NarwhalRoger avatar Jul 19 '22 07:07 NarwhalRoger

happy to hear. I'm using vs2019 with ,Net 4.8. still stuck

Davidkulpe avatar Jul 19 '22 09:07 Davidkulpe

@Davidkulpe Hi, I can't open your rtsp link in VLC

Moreno-Borsalino avatar Jul 19 '22 10:07 Moreno-Borsalino

try .net core, instead of .net framework. this worked for me.

alatriste-lee avatar Jul 24 '22 13:07 alatriste-lee

I managed to make it work by using the .net core version. Then I realized the only difference is this dll in the bin folder bin/Debug/dll/x64/opencv_videoio_ffmpeg460_64.dll. after I copied it to my .Net 4.8 project everything worked!

Davidkulpe avatar Jul 24 '22 13:07 Davidkulpe

谁能分享一下树莓派香橙派上已经编译好的文件,arm32

shenlongju avatar Oct 30 '22 13:10 shenlongju

try .net core, instead of .net framework. this worked for me.

谢谢,你的回答解决了我的问题

LFeightyFour avatar Nov 18 '22 01:11 LFeightyFour

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 21 '23 10:05 stale[bot]