Opencv-python调用树莓派SCI摄像机

树莓派打开SCI摄像机

安装SCI摄像头

sci摄像头可以自行购买,各种型号。购买之后将摄像机插入树莓派

Opencv-python调用树莓派SCI摄像机_第1张图片

开启SCI摄像头

        直接插上SCI摄像头是无法访问的,比如用opencv-python 的cap=cv2.capture(0)  cap.isOpened()  打印为True但是ret,Frame=cap.read()  ret返回False

        开启SCI摄像头,先升级一下资源库 sudo apt-get update  sudo apt-get upgrade,然后输入命令sudo raspi-config (所以还是老老实实用树莓派的系统吧),命令输入之后弹出窗口如下图:

Opencv-python调用树莓派SCI摄像机_第2张图片

Opencv-python调用树莓派SCI摄像机_第3张图片

Opencv-python调用树莓派SCI摄像机_第4张图片

后面直接按“TAB”键盘选择 Finish即可,如果首次设置Camera那么树莓派会弹出窗口请求重启树莓派,这时候重启树莓派即可。

测试命令:raspistill -o a.jpg

opencv 调用SCI摄像头

import numpy as np
import cv2


cap = cv2.VideoCapture(0) #设置摄像头 0是默认的摄像头 如果你有多个摄像头的话呢,可以设置1,2,3....
capRet = cap.isOpened()
print(f'capRet: {capRet}')
cap.set(3,1280)
cap.set(4,768)
cap.set(cv2.CAP_PROP_EXPOSURE, 0.1)
print("width={}".format(cap.get(3)))
print("height={}".format(cap.get(4)))
print("exposure={}".format(cap.get(15)))
while cap.isOpened():   #进入无限循环
    ret,frame = cap.read() #将摄像头拍到的图像作为frame值
    # frame = cv2.flip(frame, 1)  # 摄像头是和人对立的,将图像左右调换回来正常显示。
    if ret is True:
        cv2.imshow('video',frame) #将frame的值显示出来 有两个参数 前一个是窗口名字,后面是值
    else:
        print(f'ret: {ret}')
    c = cv2.waitKey(1) #判断退出的条件 当按下'Q'键的时候呢,就退出
    if c == ord('q'):  # 如果按下q 就截图保存并退出
        saveFile = "Capture.jpg"  # 带有中文的保存文件路径
        img_write = cv2.imencode(".jpg", frame)[1].tofile(saveFile)
        break
cap.release()  #常规操作
cv2.destroyAllWindows()
# 参数参考
0. CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
1. CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
2. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
3. CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
4. CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
5. CV_CAP_PROP_FPS Frame rate.
6. CV_CAP_PROP_FOURCC 4-character code of codec.
7. CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
8. CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
9. CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
10. CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
11. CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
12. CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
13. CV_CAP_PROP_HUE Hue of the image (only for cameras).
14. CV_CAP_PROP_GAIN Gain of the image (only for cameras).
15. CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
16. CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
17. CV_CAP_PROP_WHITE_BALANCE Currently unsupported
18. CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

你可能感兴趣的:(opencv,人工智能,计算机视觉)