最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法

 更新時(shí)間:2018年04月02日 08:44:43   作者:qq_31077649  
下面小編就為大家分享一篇python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

1,為了獲取視頻,你應(yīng)該創(chuàng)建一個(gè) VideoCapture 對象。他的參數(shù)可以是設(shè)備的索引號,或者是一個(gè)視頻文件。設(shè)備索引號就是在指定要使用的攝像頭。一般的筆記本電腦都有內(nèi)置攝像頭。所以參數(shù)就是 0。你可以通過設(shè)置成 1 或者其他的來選擇別的攝像頭。之后,你就可以一幀一幀的捕獲視頻了。但是最后,別忘了停止捕獲視頻。使用 ls /dev/video*命令可以查看攝像頭設(shè)備

2,cap.read() 返回一個(gè)布爾值(True/False)。如果幀讀取的是正確的,就是 True。所以最后你可以通過檢查他的返回值來查看視頻文件是否已經(jīng)到了結(jié)尾。有時(shí) cap 可能不能成功的初始化攝像頭設(shè)備。這種情況下上面的代碼會報(bào)錯(cuò)。你可以使用 cap.isOpened(),來檢查是否成功初始化了。如果返回值是True,那就沒有問題。否則就要使用函數(shù) cap.open()。你可以使用函數(shù) cap.get(propId) 來獲得視頻的一些參數(shù)信息。這里propId 可以是 0 到 18 之間的任何整數(shù)。每一個(gè)數(shù)代表視頻的一個(gè)屬性,見表其中的一些值可以使用cap.set(propId,value) 來修改,value 就是

你想要設(shè)置成的新值。例如,我可以使用 cap.get(3) 和 cap.get(4) 來查看每一幀的寬和高。默認(rèn)情況下得到的值是 640X480。但是我可以使用 ret=cap.set(3,320)和 ret=cap.set(4,240) 來把寬和高改成 320X240。

CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
• CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
• CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
• CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
• CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
• CV_CAP_PROP_FPS Frame rate.
• CV_CAP_PROP_FOURCC 4-character code of codec.
• CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
• CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
• CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
• CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
• CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
• CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
• CV_CAP_PROP_HUE Hue of the image (only for cameras).
• CV_CAP_PROP_GAIN Gain of the image (only for cameras).
• CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
• CV_CAP_PROP_CONVERT_RGB Boolean flags whether images should be converted to RGB. indicating
• CV_CAP_PROP_WHITE_BALANCE Currently unsupported
• CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend cur-rently)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import numpy
from hlf_module import hlf_define
from std_msgs.msg import String
import matplotlib.pyplot as plot
import xml.dom.minidom
import pylab
import rospy
import time
cap = cv2.VideoCapture(0)
cap.set(3,640) #設(shè)置分辨率
cap.set(4,480)
fps =cap.get(cv2.CAP_PROP_FPS) #獲取視頻幀數(shù)
face_casade = cv2.CascadeClassifier('/opt/ros/kinetic/share/OpenCV-3.2.0-dev/haarcascades/haarcascade_frontalface_default.xml')
Node_name='neck'
#print cap.isOpened()
class Detect_face():
def __init__(self):
'''定義節(jié)點(diǎn)Node_name(全局變量,而非具體名稱)'''
self.err_pub=hlf_define.err_publisher()#錯(cuò)誤消息發(fā)布者
rospy.init_node(Node_name,anonymous=True)
self.neck_puber=rospy.Publisher(hlf_define.TOPIC_ACTION_NECK,String,queue_size=10)
time.sleep(0.5)
def head_motor_value(self):#解析xml文件 獲取舵機(jī)的范圍值
dom = xml.dom.minidom.parse('/home/sb/catkin_ws/src/hlf_robot/scripts/hlf_action/head_value.xml')
#得到文檔元素對象
root = dom.documentElement
itemlist = root.getElementsByTagName('login')
item = itemlist[0]
max_value=item.getAttribute("max")
min_value=item.getAttribute("min")
return max_value,min_value
def detect_face(self):
# get a frame
#frame=cv2.imread('/home/sb/桌面/timg.jpeg')
ret, frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#轉(zhuǎn)成灰度圖
#frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
# show a frame
cv2.imshow("capture", gray)
faces = face_casade.detectMultiScale(gray,1.2,5) #檢測人臉
#print len(faces)
if len(faces)>0:#判斷是否檢測到人臉
result = ()
max_face = 0
value_x=0
for (x,y,w,h) in faces:
if (w*h > max_face): #檢測最大人臉
max_face = w*h
result = (x,y,w,h)
# max_face.append(width*height)
x=result[0]
w=result[2]
z=value_x=value_x+x+w/2
return z
else:
return 1
if __name__=='__main__':
face=Detect_face()
motor_max,motor_min= face.head_motor_value()
x=[]
i=1
while True:
try:
z=face.detect_face()
if z != 1:
x.append(z)
if len(x)>(fps-1):
true_x = int(sum(x)/30)
if(true_x>319):
motor_value=int(1500+(int(motor_max)-1500)*(true_x-319)/320)#轉(zhuǎn)換成舵機(jī)值 頭部向左轉(zhuǎn)
face.neck_puber.publish('%s'%motor_value)
elif (true_x<319):
motor_value=int(1500-(1500-int(motor_min))*(319-true_x)/320)
face.neck_puber.publish('%s'%motor_value)
x=[]
else:
if i==fps:
face.neck_puber.publish('1500')
i=1
else:
i +=1
print (U'未檢測到人臉')
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except Exception,e:
print e
cap.release()
cv2.destroyAllWindows()

以上這篇python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

东光县| 平果县| 连云港市| 宁国市| 黎平县| 阳泉市| 永德县| 锡林郭勒盟| 哈巴河县| 舒兰市| 静宁县| 来安县| 汝州市| 邢台市| 富顺县| 凤台县| 滦南县| 襄樊市| 陈巴尔虎旗| 上犹县| 淮南市| 渝北区| 苏州市| 盐池县| 诏安县| 嵊州市| 朔州市| 金寨县| 文化| 科技| 黑山县| 宁远县| 营山县| 鄯善县| 芷江| 莆田市| 平潭县| 萝北县| 仪征市| 青冈县| 临清市|