0

I have a list of n lists like this

pixels = [[400, 220, 515, 293], [433, 373, 482, 452], [401, 370, 477, 475]]

Each sublist correspond to the Top Left and Bottom Right Points for each crop

I made this code to extract a single crop from the whole list

  x1 = min(map(lambda x: x[0], pixels))
  y1 = min(map(lambda x: x[1], pixels))
  x2 = max(map(lambda x: x[2], pixels))
  y2 = max(map(lambda x: x[3], pixels))

  crop = img[y1:y2, x1:x2]
 cv2_imshow(crop)

How can I make n crops from n sublists?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
feruciform
  • 45
  • 5

1 Answers1

2

Hope It will work

import cv2
pixels = [[400, 220, 515, 293], [433, 373, 482, 452], [401, 370, 477, 475]]
for i in pixels:
    img = cv2.imread(r"img _path")
    x1,y1,x2,y2 = i
    crop = img[y1:y2, x1:x2]
Parthiban Marimuthu
  • 665
  • 1
  • 8
  • 15