我想使用blackMagic卡处理视频。 第一步显然是捕获帧,但我不知道该怎么做。 我试图使用通常的opencv代码来检测凸轮和显示框架,但它不起作用。有人知道吗?
谢谢
这是我的代码:
我正在那里录音,但没关系,这不是我想要做的主要事情 我创建了一个类来设置网络摄像头的属性,但我不认为用BMCC这样做是正确的
from Capture import Capture
import cv2
import os
from src import improcess
# video recorder
capture = cv2.VideoCapture(1)
cap = Capture(capture)
fourcc = cv2.cv.CV_FOURCC(*'MSVC') # cv2.VideoWriter_fourcc() does not exist
video_writer = cv2.VideoWriter("C:\Users\Syllia\Videos\output3.avi", fourcc, 30.0, (640, 480))
i = 0
cap.set_brightness(25)
while(capture.isOpened()):
# Capture frame-by-frame
ret, frame = cap.cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
if(i==120):
cap.adjust_brightness(100, frame)
if i >= 240 and i<360:
frame = improcess.binarize(170, frame)
if i>360:
frame = gray
video_writer.write(frame)
cv2.imshow('frame',frame)
i = i+1
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
video_writer.release()
capture.release()
cv2.destroyAllWindows()
答案 0 :(得分:0)
OpenCV视频捕获功能不支持Blackmagic设备(可能)。我使用Blackmagic Decklink SDK捕获Blackmagic相机。您可以在Blackmagic支持网站上找到并下载它: Blackmagic design support
请注意,它不支持Python或OpenCV接口,但有C ++跨平台示例,包括Windows MFC。请注意,如果我没记错的话,(颜色)像素格式可能与OpenCV不同:如果你想进行进一步的图像处理,你需要自己转换它们。
答案 1 :(得分:0)
我有同样的问题。我解决了它,它使用覆盖libvlc_video_set_callbacks的python-vlc库对帧进行编码,然后使用opencv使用已经以numpy格式转换的帧。
这是代码:
import vlc,cv2
import ctypes
import time
import sys
import numpy as np
from PIL import Image
pl = vlc.MediaPlayer('dshow://')
VIDEOWIDTH = 1280
VIDEOHEIGHT = 720
# size in bytes when RV32
size = VIDEOWIDTH * VIDEOHEIGHT * 4
# allocate buffer
buf1 = (ctypes.c_ubyte * size)()
buf2 = (ctypes.c_ubyte * size)()
# get pointer to buffer
buf_p = ctypes.cast(buf1, ctypes.c_void_p)
# global frame (or actually displayed frame) counter
framenr = 0
test=[]
# vlc.CallbackDecorators.VideoLockCb is incorrect
CorrectVideoLockCb = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p))
@CorrectVideoLockCb
def _lockcb(opaque, planes):
print "lock"
planes[0] = buf_p
ctypes.memmove(buf2, buf1, size)
#time.sleep(1)
@vlc.CallbackDecorators.VideoDisplayCb
def _display(opaque, picture):
global framenr,test
img = Image.frombuffer("RGBA", (VIDEOWIDTH, VIDEOHEIGHT), buf2, "raw", "BGRA", 0, 1)
#img.save('img{}.png'.format(framenr))
#print "display {}".format(framenr)
# shouldn't do this here! copy buffer fast and process in our own thread, or maybe cycle
# through a couple of buffers, passing one of them in _lockcb while we read from the other(s).
#img.save('img{}.png'.format(framenr))
#img=cv2.cvtColor(np.array(img), cv2.COLOR_BGRA2RGB)
frame_CV=np.array(img)
framenr+=1
print "frame",framenr,frame_CV.shape
test=frame_CV
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(test,"Test",(50,50), font, 0.7,(250,20,30),1,cv2.LINE_AA)
#cv2.imshow("Test",test)
#cv2.waitKey(1)
#if framenr==10:
#cv2.imshow("Test",test)
#print "OpenCV"
#------------------------------------------------------------------------------
# MAIN CYCLE
#------------------------------------------------------------------------------
vlc.libvlc_video_set_callbacks(pl, _lockcb, None, _display, None)
pl.video_set_format("RV32", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4)
pl.play()
#10 seconds are necessary to consolidate memory buffer exchange and library
#syncronization
time.sleep(10)
while True:
cv2.imshow("Test",test)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
pl.stop()
cv2.destroyAllWindows()
#time.sleep(10)
#------------------------------------------------------------------------------