Skip to main content

OpenCV Read Video and Resize in Python

 OpenCV Read Video and Resize


import cv2
width = 360
height = 240
cap = cv2.VideoCapture("readvideo.mp4")
while True:
success, img = cap.read()
img = cv2.resize(img, (width, height))
cv2.imshow("frame", img)
if cv2.waitKey(1) and 0xFF == ord('q'):
break

Comments

Popular posts from this blog

OpenCV Capture Image From Camera

Capture Image From Camera Using OpenCV, you can capture video from your computer's webcam and use these videos for many purposes. OpenCV provides a very simple interface for video capture process. It takes preparation to capture video. To capture a video, you must create a VideoCapture object. Its argument may be the device index. capture = cv2.VideoCapture( 0 )   The device index is just the number that determines which camera to use. Normally 0 is selected if a camera will be connected. You can select the second camera by giving a value of 1. After that, you can shoot frame by frame. ret , frame = capture.read()   cap.read () returns a bool value. If the frame reads correctly, the value will be True. With the Cap.isOpened () method, you can check whether the video capture process is started. If it's true, it's okay. If not, you need to open it using cap.open (). The codes are all as follows: import cv2 capture = cv2.VideoCapture( 0 ) while ( True ):   # C

Show OpenCV Image With Matplotlib

Show Image With Matplotlib Matplotlib is a drawing library that offers a wide variety of drawing methods for Python. Matplotlib; The basic python library we use in data visualization. It allows us to make 2 and 3 dimensional drawings. In order to use Matplotlib, we need to add it to our project as follows: from matplotlib import pyplot as plt The image is read as follows: img = cv2.imread( 'bird.jpg' )   Finally, the captured image is displayed on the screen with the following code: plt.imshow(img) plt.xticks([]) , plt.yticks([]) plt.show() Code and output are as follows: import cv2 from matplotlib import pyplot as plt img = cv2.imread( 'bird.jpg' ) plt.imshow(img) plt.xticks([]) , plt.yticks([]) plt.show() Output:  

Opencv Image Properties - rows, columns and channels, type of image data, number of pixels

Opencv Image Properties  OpenCV allows access to image properties. These properties are rows, columns and channels, type of image data, number of pixels. The img.shape command is used to access the shape of the image. Returns rows, columns and channels. import  cv2 img = cv2.imread( 'flower.jpg' ) print (img.shape) Result: (400, 400, 3) The data type of the image is obtained with img.dtype import cv2 img = cv2.imread( 'flower.jpg' ) print (img.dtype) Result: uint8