Thread: Network Tables
View Single Post
  #3   Spotlight this post!  
Unread 30-03-2014, 15:56
lucas.alvarez96's Avatar
lucas.alvarez96 lucas.alvarez96 is offline
Registered User
AKA: Lucas Alvarez
FRC #2576 (Chilean Heart)
 
Join Date: Dec 2013
Rookie Year: 2013
Location: Chile
Posts: 123
lucas.alvarez96 is a name known to alllucas.alvarez96 is a name known to alllucas.alvarez96 is a name known to alllucas.alvarez96 is a name known to alllucas.alvarez96 is a name known to alllucas.alvarez96 is a name known to all
Re: Network Tables

I'd reckon like 3 seconds of latency...my FPS is great, it's just that there has to be some problems with the buffer

Code:
import cv2
import urllib 
import numpy as np

stream=urllib.urlopen('http://10.25.76.11/mjpg/video.mjpg')
bytes=''
while True:
    bytes+=stream.read(16384)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
        cv2.imshow('i',i)
        if cv2.waitKey(1) ==27:
            exit(0)
I got the code from StackOverflow. I had tried using a simple VideoCapture(ip), and got it to work on C++, but Python just throws up some errors:

Code:
Traceback (most recent call last):
  File "C:\Users\Lucas\Documents\opencv\opencv\webcam.py", line 7, in <module>
    cv2.imshow("window", img)
error: C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
And when I print out the value of "ret" (the first variable outputted by VideoCapture::read()), I get False, which indicates that there is no image being captured (duh).

Any ideas?
__________________
FRC 2576 2015-2016: Mentor
FRC 2576 2013-2015: Programmer & Chairman's Presenter

Los Angeles Regional 2014: Regional Chairman's Award