在Opencv中捕获视频时出现问题

时间:2019-02-08 14:04:55

标签: python-3.x opencv3.0

我没有截屏。我正在使用cv2软件包,我想知道我的代码中是否缺少稳定功能。

cap=cv2.VideoCapture(0);    
bg = cv2.flip(cap.read()[1],1);
w = np.shape(bg)[1];
h = np.shape(bg)[0];
bg = bg[1:h-199,250:w].copy();
app = wx.App(False);
(sx,sy) = wx.GetDisplaySize();

    frame = cv2.flip(cap.read()[1],1);
    roi = frame[1:h-199,250:w].copy();
    temp_roi = roi.copy();
    fmask=cv2.absdiff(bg,roi,0);
    fmask=cv2.cvtColor(fmask,cv2.COLOR_BGR2GRAY);
    fmask=cv2.threshold(fmask,10,255,0)[1];
    ##Morphological Processing########
    fmask=cv2.erode(fmask,cv2.getStructuringElement(cv2.MORPH_ERODE,(2,2)),iterations=2);
    mask1=cv2.morphologyEx(fmask,cv2.MORPH_CLOSE,cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(4,4)));
    mask1=cv2.erode(mask1,cv2.getStructuringElement(cv2.MORPH_ERODE,(2,2)),iterations=2);
    cv2.imshow('mask1',mask1);
    fg_frame=cv2.bitwise_and(roi,roi,mask=mask1);
    cv2.imshow('fg_frame',fg_frame);
    gr_frame=cv2.cvtColor(fg_frame,cv2.COLOR_BGR2GRAY);
    gr_frame=cv2.blur(gr_frame,(10,10));
    bw_frame=cv2.threshold(gr_frame,50,255,0)[1];
    ############ Tracking the hand contour ################
    con=cv2.findContours(bw_frame,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[1];

我希望获得像捕获我的面部手势那样的输出。但是,我仍然失败了,它似乎没有捕获黑屏。有人可以帮我吗?

0 个答案:

没有答案