The Live video resolution is around 4000x3000 pixels whose image has been displayed in the attachment. Could it be possible to detect the object, crop the image?
With some Earlier code, I am able to detect them object only but I am facing the issue of camera shit process in OpenCV
Note: The Image detection process was done with laptop webcam using mentioned below code:
import cv2
import numpy as np
video = cv2.VideoCapture("output.avi")
_, first_frame = video.read()
x = 210
y = 310
width = 230
height = 115
roi = first_frame[y: y + height, x: x + width]
hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
roi_hist = cv2.calcHist([hsv_roi], [0], None, [180], [0, 180])
roi_hist = cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX)
term_criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
print(term_criteria)
while True:
_, frame = video.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.calcBackProject([hsv], [0], roi_hist, [0, 180], 1)
_, track_window = cv2.meanShift(mask, (x, y, width, height), term_criteria)
x, y, w, h = track_window
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("Mask", mask)
cv2.imshow("Frame", frame)
key = cv2.waitKey(60)
if key == 27:
break
video.release()
cv2.destroyAllWindows()
Suggestion Regarding this will be a great help