cv2.VideoCapture(0).set/get

pencv自带的VideoCapture()函数定义摄像头对象,其参数0表示第一个摄像头,一般就是笔记本的内建摄像头。 cap = cv2.VideoCapture("../test.avi") 逐帧显示实现视频播放 在while循环中,利用视频对象的read()函数读取视频的某帧,并显示


class VideoCapture(builtins.object)

 |  Methods defined here:

 |  

 |  __init__(self, /, *args, **kwargs)

 |      Initialize self.  See help(type(self)) for accurate signature.

 |  

 |  __new__(*args, **kwargs) from builtins.type

 |      Create and return a new object.  See help(type) for accurate signature.

 |  

 |  __repr__(self, /)

 |      Return repr(self).

 |  

 |  get(...)

 |      get(propId) -> retval

 |      .   @brief Returns the specified VideoCapture property

 |      .   

 |      .   @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)

 |      .   or one from @ref videoio_flags_others

 |      .   @return Value for the specified property. Value 0 is returned when querying a property that is

 |      .   not supported by the backend used by the VideoCapture instance.

 |      .   

 |      .   @note Reading / writing properties involves many layers. Some unexpected result might happens

 |      .   along this chain.

 |      .   @code {.txt}

 |      .   `VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware`

 |      .   @endcode

 |      .   The returned value might be different from what really used by the device or it could be encoded

 |      .   using device dependant rules (eg. steps or percentage). Effective behaviour depends from device

 |      .   driver and API Backend

 |  

 |  grab(...)

 |      grab() -> retval

 |      .   @brief Grabs the next frame from video file or capturing device.

 |      .   

 |      .   @return `true` (non-zero) in the case of success.

 |      .   

 |      .   The method/function grabs the next frame from video file or camera and returns true (non-zero) in

 |      .   the case of success.

 |      .   

 |      .   The primary use of the function is in multi-camera environments, especially when the cameras do not

 |      .   have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that

 |      .   call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way

 |      .   the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames

 |      .   from different cameras will be closer in time.

 |      .   

 |      .   Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the

 |      .   correct way of retrieving data from it is to call VideoCapture::grab() first and then call

 |      .   VideoCapture::retrieve() one or more times with different values of the channel parameter.

 |      .   

 |      .   @ref tutorial_kinect_openni

 |  

 |  isOpened(...)

 |      isOpened() -> retval

 |      .   @brief Returns true if video capturing has been initialized already.

 |      .   

 |      .   If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns

 |      .   true.

 |  

 |  open(...)

 |      open(filename) -> retval

 |      .   @brief  Open video file or a capturing device or a IP video stream for video capturing

 |      .   

 |      .   @overload

 |      .   

 |      .   Parameters are same as the constructor VideoCapture(const String& filename)

 |      .   @return `true` if the file has been successfully opened

 |      .   

 |      .   The method first calls VideoCapture::release to close the already opened file or camera.

 |      

 |      

 |      

 |      open(index) -> retval

 |      .   @brief  Open a camera for video capturing

 |      .   

 |      .   @overload

 |      .   

 |      .   Parameters are same as the constructor VideoCapture(int index)

 |      .   @return `true` if the camera has been successfully opened.

 |      .   

 |      .   The method first calls VideoCapture::release to close the already opened file or camera.

 |      

 |      

 |      

 |      open(cameraNum, apiPreference) -> retval

 |      .   @brief  Open a camera for video capturing

 |      .   

 |      .   @overload

 |      .   

 |      .   Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference.

 |      .   Definitely, is same as open(int index) where `index=cameraNum + apiPreference`

 |      .   @return `true` if the camera has been successfully opened.

 |      

 |      

 |      

 |      open(filename, apiPreference) -> retval

 |      .   @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference

 |      .   

 |      .   @overload

 |      .   

 |      .   Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference)

 |      .   @return `true` if the file has been successfully opened

 |      .   

 |      .   The method first calls VideoCapture::release to close the already opened file or camera.

 |  

 |  read(...)

 |      read([, image]) -> retval, image

 |      .   @brief Grabs, decodes and returns the next video frame.

 |      .   

 |      .   @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty.

 |      .   @return `false` if no frames has been grabbed

 |      .   

 |      .   The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the

 |      .   most convenient method for reading video files or capturing data from decode and returns the just

 |      .   grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more

 |      .   frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()).

 |      .   

 |      .   @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video

 |      .   capturing structure. It is not allowed to modify or release the image! You can copy the frame using

 |      .   :ocvcvCloneImage and then do whatever you want with the copy.

 |  

 |  release(...)

 |      release() -> None

 |      .   @brief Closes video file or capturing device.

 |      .   

 |      .   The method is automatically called by subsequent VideoCapture::open and by VideoCapture

 |      .   destructor.

 |      .   

 |      .   The C function also deallocates memory and clears \*capture pointer.

 |  

 |  retrieve(...)

 |      retrieve([, image[, flag]]) -> retval, image

 |      .   @brief Decodes and returns the grabbed video frame.

 |      .   

 |      .   @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty.

 |      .   @param flag it could be a frame index or a driver specific flag

 |      .   @return `false` if no frames has been grabbed

 |      .   

 |      .   The method decodes and returns the just grabbed frame. If no frames has been grabbed

 |      .   (camera has been disconnected, or there are no more frames in video file), the method returns false

 |      .   and the function returns an empty image (with %cv::Mat, test it with Mat::empty()).

 |      .   

 |      .   @sa read()

 |      .   

 |      .   @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video

 |      .   capturing structure. It is not allowed to modify or release the image! You can copy the frame using

 |      .   :ocvcvCloneImage and then do whatever you want with the copy.

 |  

 |  set(...)

 |      set(propId, value) -> retval

 |      .   @brief Sets a property in the VideoCapture.

 |      .   

 |      .   @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)

 |      .   or one from @ref videoio_flags_others

 |      .   @param value Value of the property.

 |      .   @return `true` if the property is supported by backend used by the VideoCapture instance.

 |      .   @note Even if it returns `true` this doesn't ensure that the property

 |      .   value has been accepted by the capture device. See note in VideoCapture::get()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import timefrom serial import Serialimport serial.tools.list_portsimport cv2import numpy as npcap1 = cv2.VideoCapture("/Users/yankaipan/Desktop/stand.mp4")cap2 = cv2.VideoCapture("/Users/yankaipan/Desktop/apple.mp4")cap3 = cv2.VideoCapture("/Users/yankaipan/Desktop/bamboo.mp4")cap4 = cv2.VideoCapture("/Users/yankaipan/Desktop/rubbish.mp4")port_list = list(serial.tools.list_ports.comports())port_list_1 = list(port_list[2])port_serial = port_list_1[0]arduinoData = serial.Serial(port_serial, 9600)time.sleep(1)while True: while (arduinoData.inWaiting() == 0): pass dataPacket = arduinoData.readline() dataPacket = dataPacket.decode().strip() print(dataPacket) time.sleep(3) if dataPacket == "a": while cap1.isOpened(): ret, frame = cap1.read() if ret == True: cv2.imshow('Frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break else: cap1.set(cv2.CAP_PROP_POS_FRAMES, 0) elif dataPacket == "b": while cap2.isOpened(): ret, frame = cap2.read() if ret == True: cv2.imshow('Frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break else: cap2.set(cv2.CAP_PROP_POS_FRAMES, 0) elif dataPacket == "c": while cap3.isOpened(): ret, frame = cap3.read() if ret == True: cv2.imshow('Frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break else: cap3.set(cv2.CAP_PROP_POS_FRAMES, 0) elif dataPacket == "d": while cap4.isOpened(): ret, frame = cap4.read() if ret == True: cv2.imshow('Frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break else: cap4.set(cv2.CAP_PROP_POS_FRAMES, 0)cv2.destroyAllWindows()怎样修改代码能够让其中一个视频播放时,能够触发另一视频并播放?
05-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值