I have data similar to the following :
10-0 = [
[1915, 387, 1933, 402],
[3350, 387, 3407, 391],
[842, 505, 863, 521],
]
10-0 being the credentials of an image(to find the path) and the values inside are coordinates of a box or rectangle each, the formula i'm working on is cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
, note that 10-0 is the key of one element of a dictionary.
My code :
import cv2
for key in my_dict:
folder_blueprint = re.findall(r'\d+', key)
img = PATH_TO_SOURCE+str(folder_blueprint[0])+'-'+str(folder_blueprint[1])+'.png'
for line in key:
line_number = 0
cv2.rectangle(img,( my_dict[key][line_number][0],my_dict[key][line_number][1]),(my_dict[key][line_number][2],my_dict[key][line_number][3]),(255,0,0),2)
# cv2.imread(img)
line_number = line_number + 1
cv2.imwrite(FULL_PATH_TO_DESTINATION, img)
cv2.imshow(FULL_PATH_TO_DESTINATION, img)
k = cv2.waitKey(0) # 0==wait forever
What i finally want is the image with red boxes around the regions of interest in a new destination folder leaving the original image intact. And i have referred to similar questions on here with the same error message but they weren't helpful to my case.