PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How to make crops from list of lists

 July 26, 2022     bounding-box, crop, numpy, opencv, python     No comments   

Issue

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?


Solution

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]


Answered By - Parthiban Marimuthu
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing