Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenVideoCapture fails to load streams #445

Open
TheTomer opened this issue May 9, 2019 · 11 comments
Open

OpenVideoCapture fails to load streams #445

TheTomer opened this issue May 9, 2019 · 11 comments
Labels

Comments

@TheTomer
Copy link

TheTomer commented May 9, 2019

Hi, I'm trying to stream an MJPEG video using GoCV, but opening the when I try to read the capture, it fails. I'm fairly new to Go so I'm probably doing something wrong here, but I'm trying to replicate a code that's working for me in Python with OpenCV.

`package main

import (
"fmt"
"gocv.io/x/gocv"
)

func main() {

streamUrl := "http://187.157.229.132:80/mjpg/video.mjpg"
capture, _ := gocv.OpenVideoCapture(streamUrl)
window := gocv.NewWindow("Stream")
defer window.Close()
frame := gocv.NewMat()
defer frame.Close()

for  {
	if ok:= capture.Read(&frame); !ok {
		fmt.Printf("cannot read stream %s\n", streamUrl)
		return
	}
	window.IMShow(frame)
	window.WaitKey(1)
}

}`

This ends up failing at the if command. What am I doing wrong here?

I'm using Go 1.12, GoCV 0.19.0 and OpenCV 4.0.1 on Windows 10.

@deadprogram
Copy link
Member

Hi @TheTomer take a look at the capwindow example, which shows the bucolic webcam scene when streaming that URL:

$ go run ./cmd/capwindow/main.go http://187.157.229.132/mjpg/video.mjpg
Start reading device: http://187.157.229.132/mjpg/video.mjpg

Hope that helps!

@TheTomer
Copy link
Author

TheTomer commented May 9, 2019

Hi deadprogram, that same script doesn't seem to work on my end, I'm getting this error:

C:\Users\Tomer\go\src\gocv.io\x\gocv>go run ./cmd/capwindow/main.go http://187.157.229.132/mjpg/video.mjpg
Error opening video capture device: http://187.157.229.132/mjpg/video.mjpg

@TheTomer TheTomer changed the title OpenVideoCapture fails loading streams OpenVideoCapture fails to load streams May 9, 2019
@deadprogram
Copy link
Member

Might be something to do with Windows? I'd check your Windows firewall settings possibly. It runs fine on my Linux install.

I am running same OpenCV/GoCV version in my tests.

$ go run ./cmd/version/main.go 
gocv version: 0.19.0
opencv lib version: 4.0.1

@TheTomer
Copy link
Author

TheTomer commented May 9, 2019

I don't think that's it, as I've allowed an exception for Go and Goland through the Windows Firewall but still getting nothing, while a matching script for Python's OpenCV works well.

On a side note, this script works correctly when streaming the laptop's webcam.

@deadprogram
Copy link
Member

Not too sure as I do not use Windows regularly. Also, I only have Windows in a VM, so that also impacts a few things, but there is not any code that is OS specific in GoCV that is not in OpenCV itself.

Are you using the same OpenCV installation for Python as you are for GoCV? If not, just wondering if any compilation flags are different.

@TheTomer
Copy link
Author

It's not the same installation, the one I use for Python was installed through Conda and it's version is 4.1.0.

The compilation flags for GoCV were these:

cmake C:\opencv\opencv-4.0.1 -G "MinGW Makefiles" -BC:\opencv\build -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=C:\opencv\opencv_contrib-4.0.1\modules -DBUILD_SHARED_LIBS=ON -DWITH_IPP=OFF -DWITH_MSMF=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_DOCS=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_saliency=OFF -DCPU_DISPATCH= -DOPENCV_GENERATE_PKGCONFIG=ON -Wno-dev

I'm not sure about how to get that info for the conda package.

@deadprogram
Copy link
Member

I was just looking at this issue's comments again, and was thinking that adding the exception for Go and Goland to Windows Firewall might not be the correct needed setting. You might need to add the executable that you are building using GoCV/OpenCV not the Go compiler itself.

@TangShuancheng
Copy link

@deadprogram I have also encountered this problem, in the win10 environment, it shows Error opening capture device: Error opening file,I don't know why.
gocv version: 0.23.0
opencv lib version: 4.3.0

@GlennZeng
Copy link

@deadprogram @TheTomer @TangShuancheng
I have also encountered this problem, in the win7 environment, it shows:
Error opening file: rtsp://admin:Qwer1234@192.168.15.213
gocv v0.27.0
opencv lib version: 4.5.0
The laptop's built-in camera can be successfully accessed
But access to the external camera via rtsp fails
I have tested that vlc can successfully access the external camera

@GlennZeng
Copy link

@deadprogram @TangShuancheng @TheTomer
Do you have a solution?

@TheTomer
Copy link
Author

I ended up sticking with Python, so nothing too innovative on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants