lovermonkey
Posts: 73
Joined: Wed Oct 14, 2015 4:50 am

OPencv works locally but not thru network

Sun Jan 07, 2018 2:14 am

I have the basic face detection python program running on my raspberry pi. It works with no issues. But I was trying to log in to the pi thru another computer and run the same python program it gives me errors like the video isn't working. What am I doing wrong. Do I need to force the RPI to use its monitor to get this work or what? Any suggestions? Keep in mind I am not trying to stream to another computer.

lovermonkey
Posts: 73
Joined: Wed Oct 14, 2015 4:50 am

Re: OPencv works locally but not thru network

Sun Jan 07, 2018 3:08 am

Here is an example of the program I am using. Again it works great when I am actually on the RPI but when I log in ssh I get the resulting error.

[email protected]:~/Desktop/face $ cat webcam_cv3.py

import cv2
import sys
import logging as log
import datetime as dt
from time import sleep

cascPath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
log.basicConfig(filename='webcam.log',level=log.INFO)

video_capture = cv2.VideoCapture(0)
anterior = 0

while True:
if not video_capture.isOpened():
print('Unable to load camera.')
sleep(5)
pass

# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

if anterior != len(faces):
anterior = len(faces)
log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now()))


# Display the resulting frame
cv2.imshow('Video', frame)


if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Display the resulting frame
cv2.imshow('Video', frame)

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()



cat

Here is the error I am getting.


[email protected]:~/Desktop/face $ sudo python webcam_cv3.py
Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
Unable to init server: Could not connect: Connection refused

(Video:1363): Gtk-WARNING **: cannot open display:
[email protected]:~/Desktop/face $

lovermonkey
Posts: 73
Joined: Wed Oct 14, 2015 4:50 am

Re: OPencv works locally but not thru network

Sun Jan 07, 2018 6:45 am

I really hope someone chimes in here. Anyway, I have been reading that DISPLAY=:0.0 might work. I tried a few different examples but couldn't get it to work.

I did something that worked. But I wonder if there is a better way. Anyway, I was able to send xhost + on my RPI and it worked. I was able to turn on the video on the pi with no issues.

Is there a better way to do the same without xhost? Anyyone?

jeje_the_toad
Posts: 2
Joined: Tue Jun 12, 2018 2:16 pm

Re: OPencv works locally but not thru network

Thu Jun 21, 2018 6:14 am

Hello, Have you resolved your problem ?
I have exactly the same issue....
thank you for any tips
Jérôme

Return to “General programming discussion”

Who is online

Users browsing this forum: lordcenzin and 2 guests