|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Network Tables
Yeah, I know everybody has asked for this before, but I really need a Network Tables library for C++. I'd used pynetworktables and had a fully functioning code with Python, but the latency while using an Axis IP cam (even while connected to my laptop's ethernet port) is too dang high! When I tried C++, it worked like a charm, but there's no network table implementation for sending simple values such as x and y coordinates. Network sockets are sort of intimidating, and I haven't the faintest on how to implement them on our DS (with C++ and the openCV library) and the robot (using java). I would be truly grateful if someone could send me a part of their sockets code, just to get an idea on how to code it.
Thanks in advance! ![]() Last edited by lucas.alvarez96 : 29-03-2014 at 18:13. Reason: oops |
|
#2
|
||||
|
||||
|
Re: Network Tables
How high is the latency? We haven't had any significant problems with it, and all of our code is implemented in python (robot + image processing + custom dashboard).
|
|
#3
|
||||
|
||||
|
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)
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
Any ideas? |
|
#4
|
||||
|
||||
|
Re: Network Tables
I use this:
Code:
vc = cv2.VideoCapture()
vc.set(cv2.cv.CV_CAP_PROP_FPS, 1)
if not vc.open('http://%s/mjpg/video.mjpg' % self.camera_ip):
return
while True:
retval, img = vc.read(buffer)
...
|
|
#5
|
||||
|
||||
|
Re: Network Tables
Ok so I tried this:
Code:
import cv2
import numpy as np
import time
camera_ip = "10.25.76.11"
vc = cv2.VideoCapture()
vc.set(cv2.cv.CV_CAP_PROP_FPS, 1)
if not vc.open('http://%s/mjpg/video.mjpg' % camera_ip):
time.sleep(0)
while True:
retval, img = vc.read(buffer)
cv2.imshow("img", img)
if cv2.waitKey(20) == 27:
break
cv2.destroyAllWindows()
exit(0)
Code:
Traceback (most recent call last):
File "C:/Users/Lucas/Desktop/cdch/render_stream3.py", line 14, in <module>
retval, img = vc.read(buffer)
TypeError: <unknown> is not a numpy array
And yeah, I'd read somewhere that ffmpeg could sometimes be the source of the problem, but I'm on windows and haven't the faintest idea on how to compile from source... I'm very sorry Dustin if the problem is to obvious, but I've been struggling with this for weeks and my team REALLY needs it for the championships... |
|
#6
|
||||
|
||||
|
Re: Network Tables
Sorry, I copy/pasted that incorrectly. You should remove the buffer from the vc.read() call for initial testing. buffer happens to be a python keyword, and I was using it as a variable, so I wasn't allocating a new image buffer each time. So it was actually something like...
Code:
h = vc.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
w = vc.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
capture_buffer = np.empty(shape=(h, w, 3), dtype=np.uint8)
while True:
retval, img = vc.read(capture_buffer)
|
|
#7
|
||||
|
||||
|
Re: Network Tables
Yeaaaaah.....same error....
Code:
Traceback (most recent call last):
File "C:\Users\Lucas\Desktop\cdch\render_stream3.py", line 19, in <module>
cv2.imshow("img", img)
error: C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
Code:
import cv2
import numpy as np
import time
camera_ip = "10.25.76.11"
vc = cv2.VideoCapture()
vc.set(cv2.cv.CV_CAP_PROP_FPS, 1)
if not vc.open('http://%s/mjpg/video.mjpg' % camera_ip):
time.sleep(0)
h = vc.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
w = vc.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
capture_buffer = np.empty(shape=(h, w, 3), dtype=np.uint8)
while True:
retval, img = vc.read(capture_buffer)
cv2.imshow("img", img)
if cv2.waitKey(20) == 27:
break
cv2.destroyAllWindows()
exit(0)
|
|
#8
|
||||
|
||||
|
Re: Network Tables
Interesting. Don't pass it a capture buffer then, and see what happens.
|
|
#9
|
||||
|
||||
|
Re: Network Tables
Wait, the error is on the imshow. Odd. What type/shape is the image?
Code:
print img print img.shape print img.type |
|
#10
|
||||
|
||||
|
Re: Network Tables
With or without buffer, there's a problem with the capture. retval returns false, and the img array returns None, so I can't print img.shape or img.type.
Code:
AttributeError: 'NoneType' object has no attribute 'shape' |
|
#11
|
||||
|
||||
|
Re: Network Tables
Odd. That's very strange. Must be something with the way your ffmpeg is compiled.
|
|
#12
|
||||
|
||||
|
Re: Network Tables
Quote:
|
|
#13
|
||||
|
||||
|
Re: Network Tables
Quote:
Quote:
|
|
#14
|
||||
|
||||
|
Re: Network Tables
Quote:
https://www.youtube.com/watch?v=nLmviNrMers Shows a demo of everything... and in here is a link to the first forge... I'll include here for convenience: http://firstforge.wpi.edu/sf/projects/smartcppdashboard Now... this code is due for an update, but we are just about ready to head out to Lonestar regionals... so after that I may get the code all updated probably in the next two weeks, but in its current state it should get you going pretty well. Here is a sneak peak of what the newer stuff can do (not yet checked in there): https://www.youtube.com/watch?v=fccxxlvMqY0 |
|
#15
|
||||
|
||||
|
Re: Network Tables
I think he's talking about this: http://firstforge.wpi.edu/sf/sfmain/...rtcppdashboard
The opencv files should be structured something like so: Code:
C:\Python27\opencv_ffmpeg2xx.dll C:\Python27\lib\site-packages\cv2.pyd |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|