亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

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

你想要設(shè)置成的新值。例如,我可以使用 cap.get(3) 和 cap.get(4) 來(lái)查看每一幀的寬和高。默認(rèn)情況下得到的值是 640X480。但是我可以使用 ret=cap.set(3,320)和 ret=cap.set(4,240) 來(lái)把寬和高改成 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')
#得到文檔元素對(duì)象
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) #檢測(cè)人臉
#print len(faces)
if len(faces)>0:#判斷是否檢測(cè)到人臉
result = ()
max_face = 0
value_x=0
for (x,y,w,h) in faces:
if (w*h > max_face): #檢測(cè)最大人臉
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'未檢測(cè)到人臉')
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except Exception,e:
print e
cap.release()
cv2.destroyAllWindows()

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

相關(guān)文章

  • 詳解python字符串駐留技術(shù)

    詳解python字符串駐留技術(shù)

    在本文中,我們將深入研究 Python 的內(nèi)部實(shí)現(xiàn),并了解 Python 如何使用一種名為字符串駐留(String Interning)的技術(shù),實(shí)現(xiàn)解釋器的高性能。
    2021-05-05
  • python 下載文件的幾種方法匯總

    python 下載文件的幾種方法匯總

    這篇文章主要介紹了python 下載文件的幾種方法匯總,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2021-01-01
  • Python考拉茲猜想輸出序列代碼實(shí)踐

    Python考拉茲猜想輸出序列代碼實(shí)踐

    這篇文章主要介紹了Python考拉茲猜想輸出序列代碼實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • python的格式化輸出(format,%)實(shí)例詳解

    python的格式化輸出(format,%)實(shí)例詳解

    Python中格式化字符串目前有兩種陣營(yíng):%和format,哪一種比較適合我們使用呢?下面腳本之家小編給大家介紹下python的格式化輸出(format,%)實(shí)例詳解,感興趣的朋友一起看看吧
    2018-06-06
  • Gradio機(jī)器學(xué)習(xí)模型快速部署工具應(yīng)用分享

    Gradio機(jī)器學(xué)習(xí)模型快速部署工具應(yīng)用分享

    這篇文章主要為大家介紹了Gradio機(jī)器學(xué)習(xí)模型快速部署工具應(yīng)用分享原文翻譯,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • python實(shí)現(xiàn)猜拳小游戲

    python實(shí)現(xiàn)猜拳小游戲

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)猜拳小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Python實(shí)現(xiàn)數(shù)據(jù)庫(kù)編程方法詳解

    Python實(shí)現(xiàn)數(shù)據(jù)庫(kù)編程方法詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)數(shù)據(jù)庫(kù)編程方法,較為詳細(xì)的總結(jié)了Python數(shù)據(jù)庫(kù)編程涉及的各種常用技巧與相關(guān)組件,需要的朋友可以參考下
    2015-06-06
  • Python?IDLE?Subprocess?Connection?Error的簡(jiǎn)單解決方法

    Python?IDLE?Subprocess?Connection?Error的簡(jiǎn)單解決方法

    最近用要Python處理一點(diǎn)事,就打開(kāi)Python IDLE,結(jié)果出現(xiàn)錯(cuò)誤,下面這篇文章主要給大家介紹了關(guān)于Python?IDLE?Subprocess?Connection?Error的簡(jiǎn)單解決方法,需要的朋友可以參考下
    2023-01-01
  • 用Python遍歷C盤dll文件的方法

    用Python遍歷C盤dll文件的方法

    這篇文章主要介紹了用Python遍歷C盤dll文件的方法,用fnmatch模塊實(shí)現(xiàn)起來(lái)非常簡(jiǎn)單,需要的朋友可以參考下
    2015-05-05
  • 詳解用python計(jì)算階乘的幾種方法

    詳解用python計(jì)算階乘的幾種方法

    這篇文章主要介紹了詳解用python計(jì)算階乘的幾種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評(píng)論