How to connect GoPro Hero 4 live translator to openCV using Python?

I'm having trouble trying to capture a live stream from my new GoPro Hero 4 camera and do some image processing on it using openCV.

Here is my trial version (nothing is displayed in the created window

import cv2
import argparse
import time
import datetime
from goprohero import GoProHero


ap = argparse.ArgumentParser()
ap.add_argument("-a", "--min-area", type=int, default=500, help="minimum    area size")
args = vars(ap.parse_args())

camera = cv2.VideoCapture("http://10.5.5.9:8080/gp/gpControl/executep1=gpStream&c1=restart")
time.sleep(5)

cv2.namedWindow("", cv2.CV_WINDOW_AUTOSIZE)

firstFrame = None
noOfCars = 0
speed = 80

while True: 
    (grabbed, frame) = camera.read()
    text = "Smooth"
    print("Capturing ...")

    if not grabbed:
        print("nothing grabbed")
        break

the loop is interrupted because the capture is always false, which means that openCV received nothing.

+4
source share
3 answers

For those who wondered, I was able to get a good stream on OpenCV:

First you need to download the GoPro Python API if you have pip:

pip install goprocam

if not

git clone https://github.com/konradit/gopro-py-api
cd gopro-py-api
python setup.py install

Then run the following code in the python terminal window:

from goprocam import GoProCamera
from goprocam import constants
gopro = GoProCamera.GoPro()
gopro.stream("udp://127.0.0.1:10000")

UDP localhost, FFmpeg !

OpenCV localhost:

import cv2
import numpy as np
from goprocam import GoProCamera
from goprocam import constants
cascPath="/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
gpCam = GoProCamera.GoPro()
cap = cv2.VideoCapture("udp://127.0.0.1:10000")
while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
    cv2.imshow("GoPro OpenCV", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

. - OpenCV , , , ffmpeg > localhost > opencv opencv.

+1

, . ip , .jpg .mpeg( ) , . (,.mpeg ), cv.grab, cv.retrieve. ip-. , :)

0

I recently worked on this, but found that some solutions do not work. So, I decided to do this video tutorial (gopro streaming using opencv), hoping it would be useful to others.

0
source

All Articles