In this video lesson we show you how you can use an IP camera with your openCV program. We show you how to OMD software to find the IP cameras and RTSP steams on your local network. Once you have the RTSP address, it is relatively easy to work with the IP camera. In the video, we show you how to set up your secret file to hold your login credentials and your RTSP stream addresses. The code below shows the work we did in this lesson.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import cv2 import time import secret W=1280 H=720 tStart = time.time() fps = 0 RES = (W,H) textLowerLeft = (int(W*.01),int(H*.05)) fontFace = cv2.FONT_HERSHEY_SIMPLEX fontThickness = int(W/425) fontScale = H*.0015 fontColor = (0,0,255) print(secret.RTSP8) cam = cv2.VideoCapture(secret.RTSP1, cv2.CAP_FFMPEG) cam.set(cv2.CAP_PROP_BUFFERSIZE, 0) cam.set(cv2.CAP_PROP_POS_FRAMES, 0) cv2.namedWindow('Camera',cv2.WINDOW_GUI_NORMAL) cv2.moveWindow('Camera',0,65) cv2.resizeWindow('Camera',W,H) while True: deltaT = time.time() - tStart tStart=time.time() fps = fps*.95 + (1/deltaT)*.05 _, frame= cam.read() #frame=cv2.flip(frame,-1) myText = "FPS: "+str(round(fps,1)) cv2.putText(frame,myText,textLowerLeft,fontFace,fontScale,fontColor,fontThickness) cv2.imshow("Camera", frame) if cv2.waitKey(1)==ord('q'): break cv2.destroyAllWindows() print('Program Terminated') |