用代码画出2d bounding box

目标

bounding box的格式为[xmin ymin w h], 其中xmin对应图像的水平方向,即列。

要求效果如下:


(1)使用matlab代码
rgbImage=imread('car.png');
imshow(rgbImage)
hold on
rectangle('Position', [30, 30, 72, 42],...
	'EdgeColor','r', 'LineWidth', 3)

函数rectangle的语法为:

rectangle('Position',pos)

rectangle('Position',pos,'Curvature',cur)

解释:

rectangle('Position',pos) creates a rectangle in 2-D coordinates. Specify pos as a four-element vector of the form [x y w h] in data units. The x and y elements determine the location and the w and h elements determine the size. The function plots into the current axes without clearing existing content from the axes.


(2)使用Python版的OpenCV
import cv2
image = cv2.imread('car.png')
cv2.rectangle(image, (30,30), (30+72,30+42), (0,0,255))
cv2.imshow('original',image)
cv2.waitKey(0)

函数cv2.rectangle的语法为:

cv2.rectangle(img, (x,y), (x+w,y+h), (B,G,R), Thickness)

猜你喜欢

转载自blog.csdn.net/breeze5428/article/details/80234948