While i initialize traker:
is_track = tracker.init(frame, track_frame)
if is_track:
print("Tracker initialized!!!!!")
else:
print("It isn't work")
Whie it work, it gone to inscription “It isn’t work”. Several times i has cheked the ‘frame’ and ‘track_frame’, but it hasn’t work yet.
My frame:
frame = path.read()
My track_frame:
x,y = clic_coordinates
track_frame = (x - 30 , y - 25 , 60, 50)
By these coordinates it buits a rectangle (correct, that shape i want)
cv2.rectangle(frame, (x-30, y-25), (x + 30,y+ 25), (0, 255, 0), 2, 1)
And the whole code:
path = cv2.VideoCapture(0) #
clic_coordinates = None
coordinate_x=None
coordinate_y=None
condition=True
clicked=False
# Function for processing cliking on mause
def clicked_coordinates(event, x, y, flags, param):
global clic_coordinates
if event == cv2.EVENT_LBUTTONDOWN:
clic_coordinates = (x,y)
clicked = True
if event == cv2.EVENT_RBUTTONDOWN:
condition=False
tracker= cv2.TrackerKCF_create() #tracker type
if tracker is None:
print("Tracker initialized incorrectly")
area_track=None
is_track = False
iteration=0
cv2.namedWindow("Tracking")
cv2.setMouseCallback("Tracking",clicked_coordinates)
while condition:
ret, frame = path.read()
if not ret:
break
#cv2.imshow("Tracking",frame)
if is_track:
print("HERE GO!!!")
is_track, area_track=tracker.update(frame)
if is_track:
(x, y, w, h) = [int(v) for v in area_track]
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2, 1)
else:
cv2.putText(frame, "Object is not tracked", (50, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)
if (clicked or clic_coordinates is not None):
x,y = clic_coordinates
track_frame = (x - 30 , y - 25 , 60, 50)
cv2.rectangle(frame, (x-30, y-25), (x + 30,y+ 25), (0, 255, 0), 2, 1)
clicked=False
clic_coordinates=None
#cv2.imshow("Tracking", frame)
if track_frame is not None:
print("region for track is ok: " , track_frame)
if frame is not None:
print(f"Frame size: {frame.size}")
print("Frame ok")
try:
# ret, frame = path.read()
# if ret:
is_track = tracker.init(frame, track_frame)
if is_track:
print("Tracker initialized!!!!!")
else:
print("It isn't work(")
except cv2.error:
print(f"OpenCV error: ")
print("Tracker hasn't initialized but go")
cv2.imshow("Tracking", frame)
if cv2.waitKey(300) & 0xFF == ord('q'):
condition=False
break
cv2.imshow("Tracking", frame)
I tried everything chatGPT offered, blackbox offered: to chek frame and track_frame, to change the tracker (for example for MIL), displayed on the screen a both frames. The only hope is this forume(
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.