<jupyter_start><jupyter_text>/*** @par Copyright (C): 2010-2020, Shenzhen Yahboom Tech* @file:         Drive camera.ipynb* @author:       xiaozhen* @version：     V1.0* @date:         2020.09.20* @brief:        Drive camera display video in real time* @details:* @par History:  Description below*/<jupyter_code>import cv2
import ipywidgets.widgets as widgets
import threading
import time
 
#Set camera display component
image_widget = widgets.Image(format='jpeg', width=600, height=500)  
display(image_widget)      # display camera component                                            
#bgr 8 to jpeg format
import enum
import cv2
 
def bgr8_to_jpeg(value, quality=75):
    return bytes(cv2.imencode('.jpg', value)[1])
image = cv2.VideoCapture(0)        # Open camera
 
# 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
 
ret, frame = image.read()     # read camera data
image_widget.value = bgr8_to_jpeg(frame)
while 1:
    ret, frame = image.read()
    image_widget.value = bgr8_to_jpeg(frame)
    time.sleep(0.010)
image.release()              #Release the object after use, otherwise when the next program needs to use the object, it will be unusable because it is occupied<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11515513126491647, 'fraction_numerical': 0.056682577565632455, 'mean_word_length': 3.5202156334231804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '437676', 'license': 'MIT', 'n_tokens_mistral': 644, 'n_tokens_neox': 575, 'n_words': 155, 'path': 'tmp_project/ipynb_test/Drive camera.ipynb', 'repo_name': 'sive2045/auto_parking', 'size': '1676'}