0

This is my image book image

I have used this question to create those boxes, but I am not good with python. How do I now create 3 images from the 3 boxes that i have created? I searched the internet and i can't find the right answer. Thanks!

Dimitar
  • 1,830
  • 5
  • 32
  • 52

1 Answers1

1

Replace the below code. I have followed the link you have provided in question.

var=1
for contour in contours:
    convex_contour = cv2.convexHull(contour)
    area = cv2.contourArea(convex_contour)
    if area > AREA_THRESHOLD:
        cv2.drawContours(img, [convex_contour], -1, (255,0,0), 3)

        # get rectangle bounding contour
        [x,y,w,h] = cv2.boundingRect(contour)
        crop_img = img[y:y+h, x:x+w]
        cv2.imwrite("crop"+str(var)+".png", crop_img)
        var+=1

This will save the cropped images in current program running location in .png format

shaik moeed
  • 5,300
  • 1
  • 18
  • 54
  • that works great the only problem i have right now is that the `var` variable is not consistent. What i mean is that first image is the box on the bottom right and then the box on the left side and then the box on the right upper part, is there a way to keep the boxes from left-top to right-bottom, so the code can read them in order after that? thanks! – Dimitar May 20 '19 at 07:37
  • `var` is used just to give naming for files. The order of cropped images is depend on how the `contours` are sorted. – shaik moeed May 20 '19 at 08:37