I have written Python code that converts video to black and white mode. In the center of the video is a color ROI.
I don't understand how to write a loop that will make the ROI move (any kind of movement) through the video, so that the pixels in the region of interest are colored, and the rest is black and white. As I understand it, int data is needed for the loop. Therefore, I converted the width and height to int.
The available questions and examples on ROI bypass this topic.
Мy code:
import cv2
import numpy as np
import time
capture = cv2.VideoCapture('file path')
width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = capture.get(cv2.CAP_PROP_FPS)
print(fps, width, height)
file_count = 0
while capture.isOpened():
ret, frame = capture.read()
if ret == True:
cv2.putText(frame, 'Doc.', (0, 340),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0))
grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ROI = frame[10:32, 10:40, :]
gray2rgb = cv2.cvtColor(grayFrame, cv2.COLOR_GRAY2RGB)
gray2rgb[10:32, 10:40, :] = ROI
##### In this place I have difficulties
for i in range(height):
for j in range(width - 300):
gray2rgb[i, j + 10]
##### end of this cycle
cv2.imshow('Look', gray2rgb)
file_count += 1
print('Shot {0:04d}'.format(file_count))
key = cv2.waitKey(20)
if (key == ord('q')) or key == 27:
break
capture.release()
cv2.destroyAllWindows()