My problem is that I need to take a picture from the camera and process it with OpenCV and Python to get coordinates and send them to a robotic arm, but I can't get communication with the Cognex camera with the following code (I got it from the OpenCV documentation):
import cv2
cognex = cv2.VideoCapture('192.168.1.5')
while True:
ret, frame = cognex.read()
cv2.imshow('Cognex Camera', frame)
if cv2.readKey(1) & 0xFF == ord('q'):
break
cognex.release()
cv2.destroyAllWindows()
but when I run this example I got this error:
warning: Error opening file
(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)
warning: 192.168.1.5
(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:902)
Traceback (most recent call last):
File "ejemplo.py", line 8, in <module>
cv2.imshow('Cognex Camera', frame)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-
python\opencv\modules\highgui\src\window.cpp:352: error:
(-215:Assertion failed) size.width>0 && size.height>0 in function
'cv::imshow'
and I think it's because it doesn't open the connection with the camera. I have searched for information on the internet that can help me but I have not be able to find out if it can really connect or cannot connect OpenCV with the Cognex camera.
cv2.VideoCapture('http://192.168.1.5')pingthe camera? Where did you get its address? Have you logged into your router to see the DHCP allocations? Does it serve images over http or rtsp? Is there a port you should specify? Which camera is it? Does Cognex's own software see the camera?