如何从列表列表中制作农作物

发布于 2025-01-18 09:12:27 字数 441 浏览 3 评论 0原文

我有一个像这样的 n 个列表的列表

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

每个子列表对应于每种作物的左上点和右下点

我编写了这段代码来从整个列表中提取单个作物

  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)

如何从 n 个子列表中制作 n 种作物?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2025-01-25 09:12:27

希望它会起作用

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]

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文