cv2 控制相机

分辨率 (默认640*480)

import cv2
cap = cv2.VideoCapture(1)
cap.set(3,1280)
cap.set(4,960)
分辨率越大,视野越小

自动对焦相机清晰度检测

https://blog.csdn.net/dcrmg/article/details/53543341
https://www.cnblogs.com/arkenstone/p/7900978.html
image = "test.jpg"
frame = cv2.imread(image)
img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 将图片压缩为单通道的灰度图

img_resize = cv2.resize(img2gray, (112, 112)) # 为方便与其他图片比较可以将图片resize到同一个大小

score = cv2.Laplacian(img2gray, cv2.CV_64F).var()
print "Laplacian score of given image is ", score
if score > 100: # 这个值可以根据需要自己调节,在我的测试集中100可以满足我的需求。

print "Good image!"

else:

print "Bad image!"
发表新评论