简体   繁体   English

如何获得图像的 4 x 4 边界框及其相应的坐标?

[英]How to get 4 by 4 bounding boxes of an image and their corresponding coordinaates?

I am trying get 4 by 4 bounding boxes of an image.我正在尝试获取图像的 4 x 4 个边界框。 Like this bounding box像这个边界框

Bounding Boxes边界框

Can someone please help me how to get those bounding boxes and their coordinates?有人可以帮助我如何获得这些边界框及其坐标吗?

From my understanding, you are trying to visually split the input image to 4 squares.根据我的理解,您正在尝试将输入图像直观地拆分为 4 个方块。 In this case all you need is to draw two lines: one horizontal, one vertical.在这种情况下,您只需要画两条线:一条水平线,一条垂直线。 see Drawing Functions in OpenCV documentation .请参阅OpenCV 文档中的绘图函数 A quick example:一个简单的例子:

import cv2

height, width = input_image.shape[:2]

# for horizontal line
horizontal_left = (0, int(height / 2))
horizontal_right = (int(width), int(height / 2))

cv2.line(input_image, horizontal_left, horizontal_right, (0, 255, 0), 1)

# for vertical
vertical_top = (int(width / 2), 0)
vertical_bottom = (int(width / 2), int(height))

cv2.line(input_image, vertical_top, vertical_bottom, (0, 255, 0), 1)

To create and rectangle use this piece of code.要创建和矩形使用这段代码。

import cv2

cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)


x1,y1 ------
|          |
|          |
|          |
--------x2,y2

And if you want to draw your own ROI use this piece of code.如果您想绘制自己的投资回报率,请使用这段代码。

import cv2
import numpy as np

if __name__ == '__main__' :

    # Read image
    im = cv2.imread("image.jpg")

    # Select ROI
    r = cv2.selectROI(im)

    # Crop image
    imCrop = im[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])]

    # Display cropped image
    cv2.imshow("Image", imCrop)
    cv2.waitKey(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从图像中获取随机边界框? (蟒蛇) - How to get random bounding boxes from image? (python) 如何遍历图像绘制边界框? - How to traverse through image drawing bounding boxes? 给定具有多个边界框的图像,我如何仅突出显示完全在另一个边界框内的那些边界框? - Given an image with several bounding boxes, how do I highlight only those bounding boxes that are completely inside another bounding box? 在灰度图像上创建边界框 - Creating bounding boxes on grayscale image 显示带有边框的图像时出现问题 - Trouble Displaying an Image with Bounding Boxes 如何在图像中的多个矩形边界框内应用阈值? - How to apply threshold within multiple rectangular bounding boxes in an image? 如何使用 pytesseract 从图像中的特定边界框中提取文本? - How to extract text from specific bounding boxes in an image using pytesseract? 如何确定图像中旋转边界框的角度、中心和中点? - How to determine the angle, center, and midpoints of rotated bounding boxes in an image? 使用边界框列表从图像中裁剪多个边界框 - Crop multiple bounding boxes from image with list of bounding boxes 从图像中提取边界框并将其存储为图像? - extracting bounding boxes from an image and stores it as image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM