OpenCV - 在视频捕获期间为特定区域着色?

时间:2017-01-16 09:56:30

标签: python python-2.7 opencv video-capture opencv3.0

这是我的代码:

import cv2
import numpy as np
cap = cv2.VideoCapture(1)
fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
framesize = (640,480)
out = cv2.VideoWriter('dump.avi',fourcc,60.0,framesize)
font = cv2.FONT_HERSHEY_SIMPLEX

while True:
        ret, frame = cap.read()
        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
        cv2.imshow('frame',frame)
        cv2.rectangle(gray, (0,0),(640,480),(255,255,255),3)
        cv2.putText(gray, "gray", (0,130),font, 5,(255,255,255),2,   cv2.LINE_AA)
        cv2.imshow('fr',gray)

这里我试图为实时图像提要上的特定方形区域着色

        #gray[100:105,110:115] = [255,255,255]
        io = gray[37:111,107:194]

我在这里克隆一个是另一个

        gray[200:200,270:283] = io
        out.write(frame)        
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
out.release()
cv2.destroyAllWindows()

如何为特定区域着色?因为我的尝试不起作用。

0 个答案:

没有答案