def TrackGarbage(im, up, down, left, right, max_index, s): counter = 2 start = 2 New_Template, Template_XY = im[up:down, left:right], (up, left) # save given Garbage cv2.imwrite(GARBAGE_PATH + str(1 + max_index) + ".jpg", New_Template) # Track loop while New_Template.shape[0] <= MAX_SIZE: im = s.getNext() if counter > start + 50: f, arr = matplotlib.pyplot.subplots(1, 1) arr.imshow(im, cmap='gray') #, interpolation='nearest') matplotlib.pyplot.show() print("up, down, left, right in that order") up = int(input()) down = int(input()) left = int(input()) right = int(input()) New_Template, Template_XY = im[up:down, left:right], (up, left) cv2.imwrite(GARBAGE_PATH + str(counter + max_index) + ".jpg", New_Template) start = counter else: New_Template, Template_XY = Tracking.Track(im, New_Template, Template_XY) cv2.imwrite(GARBAGE_PATH + str(counter + max_index) + ".jpg", New_Template) counter += 1
cooAr = getNewImageCoo(refPt) #these are just the lines from 'g', copied. saves the firest image save_twenty_random(cooAr, image) diff = [0, 0] template = image[cooAr[0][Y]:cooAr[1][Y], cooAr[0][X]:cooAr[1][X]] xy = (cooAr[0][Y], cooAr[0][X]) base = pictures.index(pictureName) counter = 1 #saves the picture so it will be possible to return to it oldImage = clone.copy() while True: #reads the next image in the list image = cv2.imread(path + "/" + pictures[base + counter]) clone = image.copy() #delegates to tracking useless, xy, template, diff = Tracking.Track( image, template, xy, diff) #clones so the rectangle will not be saved imClone = image[:].copy() cv2.rectangle( imClone, (xy[1], xy[0]), (xy[1] + template.shape[1], xy[0] + template.shape[0]), (0, 255, 0), 2) cv2.imshow("image", imClone) key = cv2.waitKey(100) & 0xFF #stops the process and returns to the first image, to choose new stoplight if key == ord('s'): image = oldImage cv2.imshow("image", image) break #pauses the process to let the user decide on new borders elif key == ord('p'):