Evening all!
My questions are the following:
1.The shape of roi
is only supposed to be 200,200. Here it is showing 313,313 and Im not sure why.
2.When I switch frame
for roi
as the argument to imshow(), the result is also not the correct size of the roi. What I get is this output:
from imutils.video import VideoStream
import argparse
import cv2
import numpy as np
import imutils
import time
ap = argparse.ArgumentParser(description="Pass the .mp4 file and optional buffer size as arguments.")
ap.add_argument("-video", type=str, help="Path to the video file") .
ap.add_argument("-buffer", type=int, default=64, help="Optional max buffer size")
args = vars(ap.parse_args())
video = cv2.VideoCapture(args["video"])
time.sleep(2.0)
offsetx = 38
offsety = 5
while (video.isOpened()):
ret, frame = video.read()
frame = imutils.resize(frame, width=1280)
(screenheight, screenwidth) = frame.shape[:2]
mid_y = screenheight/2
mid_x = screenwidth /2
roi_x = (mid_x + offsetx) - 100
roi_y = (mid_y + offsety) - 100
roi = frame[int(roi_y):int(roi_x),int(roi_y)+200:int(roi_x)+200]
cv2.rectangle(frame,(int(roi_x),int(roi_y)),(int(roi_x)+200,int(roi_y)+200),(0,255,0),3)
print(int(roi_x),int(roi_y),int(roi_x)+200,int(roi_y)+200)
print(roi.shape)
cv2.imshow('frame',roi)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video.release()
cv2.destroyAllWindows()
The output of this file is:
(313, 313, 3)
578 265 778 465
...