2.Camera python driver tutorial
2.Camera python driver tutorial
cap = cv2.VideoCapture("…/1.avi")
VideoCapture("…/1.avi"), This parameter indicates that if the path of the video file is
entered, the video is opened.
2.cap.set()
Camera parameters common configuration methods:
capture.set(CV_CAP_PROP_FRAME_WIDTH, 1920); # Width
www.yahboom.com
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 1080); # Height
capture.set(CV_CAP_PROP_FPS, 30); # Frame
capture.set(CV_CAP_PROP_BRIGHTNESS, 1); # Brightness 1
capture.set(CV_CAP_PROP_CONTRAST,40); # Contrast 40
capture.set(CV_CAP_PROP_SATURATION, 50); # Saturation 50
capture.set(CV_CAP_PROP_HUE, 50); # Hue 50
capture.set(CV_CAP_PROP_EXPOSURE, 50); # Visibility 50
Parameter explanation:
#define CV_CAP_PROP_POS_MSEC 0
// Calculate the current position in milliseconds
#define CV_CAP_PROP_POS_FRAMES 1
// Calculate the current position in frame
#define CV_CAP_PROP_MODE 9
// Backend specific value indicating the current capture mode.
www.yahboom.com
#define CV_CAP_PROP_CONVERT_RGB 16
// Mark whether the image should be converted to RGB.
3.cap.isOpened()
Return true indicates open camera successful and false indicates open camera failure
4.ret,frame = cap.read()
cap.read () reads the video frame by frame. ret and frame are the two return values
of the cap.read () function.
ret is a Boolean value, if the read frame is correct, it will return true, If the file has
not been read to the end, it returns False.
Frame is the image of each frame, which is a three-dimensional matrix.
5.cv2.waitKey(n)
n represents the delay time, if the parameter is 1, it means a delay of 1ms to switch
to the next frame of image.
If the parameter is too large, such as cv2.waitKey (1000), it will freeze because of the
long delay.
The parameter is 0, such as, cv2.waitKey (0) only displays the current frame image,
which is equivalent to video pause.
About Code
Since our entire tutorial runs in JupyterLab, we must understand the various
components inside.
Here we need to use the image display component.
1.Import library
import ipywidgets.widgets as widgets
www.yahboom.com
4.Open camera and read image
image = cv2.VideoCapture(0) # Open camera
ret, frame = image.read() # Read camera data
5.Assignment to components
#Convert the image to jpeg and assign it to the video display component
image_widget.value = bgr8_to_jpeg(frame)
import cv2
import ipywidgets.widgets as widgets
import threading
import time
# width=1280
# height=960
# cap.set(cv2.CAP_PROP_FRAME_WIDTH,width) # set width of image
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT,height) # set height of image
image.set(3,600)
image.set(4,500)
image.set(5, 30) # set frame
image.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
image.set(cv2.CAP_PROP_BRIGHTNESS, 40) #set brightness -64 - 64 0.0
image.set(cv2.CAP_PROP_CONTRAST, 50) #set contrast -64 - 64 2.0
image.set(cv2.CAP_PROP_EXPOSURE, 156) #set exposure value 1.0 - 5000 156.0
www.yahboom.com
making it unusable.
The camera screen is shown below:
www.yahboom.com