shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

Videocapture does not work with rtsp #1444

Closed NarwhalRoger closed 1 year ago

NarwhalRoger commented 2 years ago

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:password@192.168.1.126: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 commented 2 years ago

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

Moreno-Borsalino commented 2 years ago

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

Davidkulpe commented 2 years ago

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:demo@ipvmdemo.dyndns.org:5541/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast

NarwhalRoger commented 2 years ago

@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.

Davidkulpe commented 2 years ago

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

Moreno-Borsalino commented 2 years ago

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

alatriste-lee commented 2 years ago

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

Davidkulpe commented 2 years ago

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!

shenlongju commented 1 year ago

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

LFeightyFour commented 1 year ago

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

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

stale[bot] commented 1 year ago

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.