gocv icon indicating copy to clipboard operation
gocv copied to clipboard

how to use gocv for ipc

Open yyf1986 opened this issue 4 years ago • 20 comments

I install gocv is ok,and use device 0 is ok,but I don't know how to use device is a IPC

yyf1986 avatar Sep 11 '19 03:09 yyf1986

Sorry what is an "IPC"? Can you please elaborate on what you are trying to do? Thanks.

deadprogram avatar Sep 23 '19 07:09 deadprogram

I want use IP Camera,like "rtsp://admin:[email protected]"

yyf1986 avatar Sep 26 '19 06:09 yyf1986

GoCV already has streaming support, for example you can use the capwindow example to stream a URL like this:

$ 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

Since OpenCV is normally built with ffmpeg and/or gstreamer, you should be able to to do something like this with the rtsp protocol:

webcam, err := gocv.OpenVideoCapture("rtsp://admin:[email protected]")

Hope that helps!

deadprogram avatar Sep 26 '19 07:09 deadprogram

I install gocv refer https://github.com/hybridgroup/gocv#windows, and when I use 0 for deviceID is ok,but use like 'rtsp://admin:[email protected]' is not ok. my code like:

package main

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

func main() {
	deviceID := "rtsp://admin:[email protected]"
	//deviceID := "http://187.157.229.132/mjpg/video.mjpg"

	webcam, err := gocv.OpenVideoCapture(deviceID)
	if err != nil {
		fmt.Printf("Error opening video capture device: %v\n", deviceID)
		return
	}
	defer webcam.Close()
	//webcam, _ := gocv.OpenVideoCapture(1)
	window := gocv.NewWindow("Hello")
	defer window.Close()

	img := gocv.NewMat()
	defer img.Close()

	fmt.Printf("Start reading device: %v\n", deviceID)

	for {
		if ok := webcam.Read(&img); !ok {
			fmt.Printf("Device closed: %v\n", deviceID)
			return
		}
		if img.Empty() {
			continue
		}

		window.IMShow(img)
		if window.WaitKey(1) == 27 {
			break
		}
	}
}

yyf1986 avatar Sep 27 '19 06:09 yyf1986

Try using quotes like the following command:

./gocv "rtsp://admin:[email protected]"

DoubleChuang avatar Oct 02 '19 09:10 DoubleChuang

D:\GoCode\src\agent>main.exe rtsp://admin:1234@[email protected] Error opening video capture device: rtsp://admin:1234@[email protected]

when I run like "main.exe 0" is ok.

yyf1986 avatar Oct 10 '19 06:10 yyf1986

I think @DoubleChuang was suggesting you use this form of the command:

main.exe "rtsp://admin:1234@[email protected]"

However from the message displayed, I do not think that is your problem.

I wonder if you might need to make some change to the Windows firewall settings to allow the compiled program to open a port. You should investigate that, I have run into similar issues in the past.

deadprogram avatar Oct 10 '19 06:10 deadprogram

@deadprogram I close the Windows firewall,but the command still not work

yyf1986 avatar Oct 10 '19 09:10 yyf1986

How did you build OpenCV?

deadprogram avatar Oct 10 '19 09:10 deadprogram

@deadprogram I install gocv refer https://github.com/hybridgroup/gocv#windows

yyf1986 avatar Oct 12 '19 01:10 yyf1986

@yyf1986 The right uri maybe rtsp://<username>:<password>@<ip>:<port>/Streaming/channels/<stream_number>, such as rtsp://admin:[email protected]:554/Streaming/channels/1/

  • <username> and <password> are the login authentication element
  • <ip> is the IP-address of camera
  • <port> is the port number of RTSP protocol, the default value is 554
  • <stream_number> is the channel number, if it is equal to 1, it indicates that the main stream is being captured; if it is equal to 2, it indicates that the secondary stream is being captured

kuailehaibin avatar Oct 12 '19 13:10 kuailehaibin

@kuailehaibin when i use vlc to play with url "rtsp://admin:[email protected]" is ok,and I use python-opencv to captured is ok with url "rtsp://admin:[email protected]"

yyf1986 avatar Oct 14 '19 08:10 yyf1986

OK

kuailehaibin avatar Oct 14 '19 11:10 kuailehaibin

when I use Ubuntu,the problem is solve.

yyf1986 avatar Oct 21 '19 11:10 yyf1986

I have the same problem. I think this maybe cause by ffmpeg? I search how to use OpenCV to play ffmpeg, and i find this need ffmpeg support. Maybe the "Windows Install" need to add build ffmpeg part?

chaoswong1981 avatar Feb 18 '20 13:02 chaoswong1981

@yyf1986 Are you unable to use it under the win10 environment and the error opening video capture device appears? This is also the case under win10, I do not know what the reason is.

TangShuancheng avatar Jul 11 '20 13:07 TangShuancheng

@TangShuancheng yes, so I use Ubuntu to use it

yyf1986 avatar Jul 15 '20 02:07 yyf1986

I come across the same problem as yours,the problem is: Error opening video capture device: rtsp://admin:[email protected]

GlennZeng avatar Jun 21 '21 01:06 GlennZeng

Hi all,

I found the same problem in my dev env Fedora 35. Compilation went well and I can read my local camera as device 0. But having the same issue to capture the remote device with rtsp protocol. I can access the device using vlc and ffplay from the same environment.

I'm wondering if it might be a problem related to the OS and the ffmpeg library ? I can see @yyf1986 on ubuntu got working and reading many other issues in this repo other users are running it without problems.

there is a way to verbose the ouput of gocv?

kind regards

alebeta90 avatar Apr 19 '22 19:04 alebeta90

Hi,

in my case, it was a problem related with the package FFMPEG of Fedora. At the moment of compiling openCV, it was not able to find FFMPEG in the system. I needed to compile FFMPEG with specific flags in order to be detected by the openCV compilation process.

This is the line to configure FFMPEG before installing openCV

sudo ./configure --pkgconfigdir=/usr/lib64/pkgconfig --incdir=/usr/include --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --disable-x86asm

Similar issue exists in the openCV repo itself.

The issue does not exist in other distros like ubuntu for example.

Hope it can help other people in future.

alebeta90 avatar Apr 20 '22 06:04 alebeta90