Skip to main content

Posts

Showing posts from October, 2021

OpenCV Get Frame Width and Height in Python

 Opencv Get Frame Width and Height import cv2 capture = cv2.VideoCapture( 'readvideo.mp4' ) if capture.isOpened(): w = capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) h = capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) w = capture.get( 3 ) h = capture.get( 4 ) f = capture.get(cv2.cv.CV_CAP_PROP_FPS)

OpenCV Read Video From Camera

 Opencv Python Read Video From Camera import cv2 captureImage = cv2.VideoCapture( 0 ) while ( True ): ret , frame = captureImage.read() gray = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY) cv2.imshow( 'image' , gray) if cv2.waitKey( 1 ) & 0xFF == ord ( 'q' ): break captureImage.release() cv2.destroyAllWindows()

OpenCV Python Webcam Control

 OpenCV Python Webcam Control import cv2 cap = cv2.VideoCapture( 0 ) if not cap.isOpened(): raise IOError ( "webcam not available" ) while True : ret , f = cap.read() f = cv2.resize(f , None, fx = 0.5 , fy = 0.5 , interpolation =cv2.INTER_AREA) cv2.imshow( 'I' , f) c = cv2.waitKey( 1 ) if c == 27 : break cap.release() cv2.destroyAllWindows()

How to Read Video in Opencv Python

How to Read Video İn Opencv Python The following code is used to read video in OpenCV python. The process of reading video in OpenCV is very similar to reading images. The video is a series of images. All frames in a video sequence must be looped over and then rendered one frame at a time. import cv2 capture = cv2.VideoCapture( 'video.mp4' ) while (capture.isOpened()): r , f = capture.read() gray = cv2.cvtColor(f , cv2.COLOR_BGR2GRAY) cv2.imshow( 'video' , gray) if cv2.waitKey( 1 ) & 0xFF == ord ( 'q' ): break capture.release() cv2.destroyAllWindows()

OpenCV Resize Image With Aspect Ratio

OpenCV Resize Image With Aspect Ratio The OpenCV resize() method, as the name suggests, resizes the image.  import cv2 def resize (i , window_height = 500 ): aspect_ratio = float (i.shape[ 1 ]) / float (i.shape[ 0 ]) window_width = window_height/aspect_ratio i = cv2.resize(i , ( int (window_height) , int (window_width))) return i img = cv2.imread( 'image.jpg' ) img_resized = resize(img , window_height = 640 ) cv2.imshow( "ResizedImage" , img_resized) cv2.waitKey( 0 ) cv2.destroyAllWindows()