Skip to content
Advertisement

How can i connect ethernet connected camera through python (Flir AX8 camera)

I am trying to connect a Flir AX8 camera through python. This camera is connected to the ethernet port of the laptop. So, the VideoCapture() isn’t recognising the port, I’ve tried all indexes for it (0, 1, 2), but it doesn’t connect. Can anyone help me that how can i connect the camera to python?

I have tried connecting through VideoCapture(1) and through VideoCapture('IP address')

Using the IP address:

import cv2, time
video=cv2.VideoCapture('http://admin:admin@IP address/')

a=0

while True:
    a=a+1
    check, frame = video.read()

    print(check)
    print(frame)

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

    cv2.imshow("Capturing",frame)

    key=cv2.waitKey(1)

    if key== ord('q'):
        break

print(a)
video.release()
cv2.destroyAllWindows

Using the index 0, 1, 2:

import cv2, time
video=cv2.VideoCapture(1)

a=0

while True:
    a=a+1
    check, frame = video.read()

    print(check)
    print(frame)

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

    cv2.imshow("Capturing",frame)

    key=cv2.waitKey(1)

    if key== ord('q'):
        break

print(a)
video.release()
cv2.destroyAllWindows

I am getting following error in both situations:

False
None
Traceback (most recent call last):
  File "C:UsersyashwDesktopex.py", line 15, in <module>
    cv2.imshow("Capturing",frame)
cv2.error: OpenCV(4.1.0) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

Advertisement

Answer

import cv2 import numpy as np

while True: cap=cv2.VideoCapture(‘http://admin:admin@169.254.253.219/snapshot.jpg?user=admin&pwd=admin&strm=0‘) ret,img=cap.read() cv2.imshow(‘videos output’,img) k=cv2.waitKey(1) if k==ord(‘q’): break

cap.release() cv2.destroyAllWindows

Advertisement