I am working on a video.mp4 file and I would like to apply some conditions for half of the frame and other conditions for the other half. One of the frames is as shown:
The idea was to process a region of interest from y[0:500]
and all x-axis (i.e: x[0:1920]
) being one region and the other region from y[500:1080]
and x[0:1920]
.
I tried to set one region of interest this way:
import cv2
#LOAD VIDEO PATH
vid = cv2.VideoCapture('video.mp4')
ret, frame = vid.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
print(gray[:,0].shape)
print(gray[0,:].shape)
for x in len(range(gray[0:1920])):
for y in len(range(gray[0:500])):
sub_image[x,y] = gray
plt.figure(figsize=(14, 7))
plt.imshow(sub_image)
But I kept on getting the error:
error: OpenCV(4.4.0) C:UsersappveyorAppDataLocalTemp1pip-req-build-6sxsq0tpopencvmodulesimgprocsrccolor.cpp:182:
error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' on line 5 (ie converting BGR TO GRAY)
Any ideas on how I can proceed?
question from:
https://stackoverflow.com/questions/65863952/obtain-region-of-interest-with-python-opencv 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…