0

I'm using openCV and EAST to do text detection. Once I've detected the areas with text, I want to crop them into multiple images. How do i crop them?

for (startX, startY, endX, endY) in boxes:

    # scale the bounding box coordinates based on the respective

    startX = int(startX * rW)
    startY = int(startY * rH)
    endX = int(endX * rW)
    endY = int(endY * rH)

    # drawing the bounding box on the image

    Final = orig[startY:endY, startX:endX]
    cv2.imshow("Text Detection", Final)
    cv2.waitKey(0)
    cv2.imwrite("test.jpg",Final)

Since it can detect multiple texts in a picture, I want it to produce multiple cropped images but I do not know how

furas
  • 134,197
  • 12
  • 106
  • 148
Nash
  • 1
  • 1
  • you have to use different names for files - now you write all images with the same name so you may get only last image. – furas Aug 02 '19 at 04:43
  • Welcome to stackoverflow. As mentioned in the comment above, you have to save the file with other name. Take the cropped image in the mat format and get the mat format converted to image format of your choice. – arqam Aug 02 '19 at 04:46

1 Answers1

1

You have to use different names for files.

You can use enumerate() and string formating to add number to filename

for number, (startX, startY, endX, endY) in enumerate(boxes):

    # ... rest ...

    cv2.imwrite("test{}.jpg".format(number), Final)

or at least use variable to count files

number = 0

for (startX, startY, endX, endY) in boxes:

    # ... rest ...

    number += 1
    cv2.imwrite("test{}.jpg".format(number), Final)
    # or
    #cv2.imwrite("test" + str(number) + ".jpg", Final)
    # or Python 3.6+
    #cv2.imwrite(f"test{number}.jpg", Final)
furas
  • 134,197
  • 12
  • 106
  • 148