我想绘制实时摄像机中随时间变化的黑色像素。但是现在可以在视频文件中工作。我可以到达视频文件中每一帧的number of black pixel,但是我想找到开始更改黑色像素的时间然后写入示例文件,直到更改停止。
def pixelHesaplayici(x):
siyaholmayanpixel=cv2.countNonZero(x)
height,width=x.shape
toplampixel=height*width
siyahpixelsayisi=toplampixel-siyaholmayanpixel
return siyahpixelsayisi
cap=cv2.VideoCapture('kumas1.mp4')
pixel_sayici=0
i=0
PixelList=[]
while(True):
ret,frame=cap.read()
frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
frame = cv2.GaussianBlur(frame,(5,5),0)
_,thresh1=cv2.threshold(frame,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imshow("frame",thresh1)
#cv2.imshow("org",frame)
cv2.imwrite("sample/frame%d.jpg"%i,thresh1)
i+=1