[英]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
像这个边界框
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.