Access Industrial Camera using Python in Jupyter notebook

Hello,
I am working on object detection model. I am using industrial camera (Dalsa Nano Genie and Blackfly S) with gigE interface to detect the object.
I can’t access the camera (using Windows and Linux).
Code:
import cv2
cap = cv2.VideoCapture(‘rtsp://192.168.24.1/1’) #(‘http://192.168.24.1:5025’)

while(True):
ret, frame = cap.read()
cv2.imshow(‘frame’,frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
cv2.destroyAllWindows()
break

Error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’

The frame window opens but don’t respond.
Can you please guide me how can I access the camera?

Hi @manpreet_kaur

Welcome to the TensorFlow Forum!

Please use below code to enable camera to capture the image and press ‘q’ to exit from the camera mode.

!pip install opencv-python

import cv2
#you can use 0 to access built-in webcam and 1, 2 for another  camera if you have multiple cameras
cam = cv2.VideoCapture(0) 
while True:
    ret, frame = cam.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):  #Press 'q' to exit
        break

cam.release()
cv2.destroyAllWindows()