目录
画框
打印文字
opencv 旋转图片
opencv旋转矩形框
cv2.rectangle(img, pt1, pt2, color, thickness, lineType, shift )
cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
im0=cv2.resize(im0,(960,540))
cv2.putText(im0, 'index:', (50, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.imshow("result", im0)
opencv 旋转图片 python c++_AI视觉网奇的博客-CSDN博客_opencv 旋转
def draw_rect(rect):
# 在im画布上画矩形rect
im = np.zeros([640, 640], dtype=np.uint8)
cv2.polylines(im, [rect], 1, 255)
plt.imshow(im)
plt.show()
def rotate_rect(rect, angle):
# 输出rect旋转后的矩形四个点的坐标,angle为正及顺时针旋转,为负及逆时针旋转
#绕矩形框的中心旋转的:实际上以图像中心旋转,这个不对
(x, y), (w, h), a = cv2.minAreaRect(rect)
rect_r = ((x, y), (w, h), a + angle)
print("angle",a)
return cv2.boxPoints(rect_r).astype(np.int32)
if __name__ == '__main__':
rect = np.array([[100, 50], [150, 50], [150, 150], [100, 150]], dtype=np.int32)
# draw_rect(rect)
rect_r=rotate_rect(rect,270)
rect_2=rotate_rect(rect,0)
points= cv2.minAreaRect(rect_r)
print("rect_r",points)
points= cv2.minAreaRect(rect_2)
print("rect_2", points)
im = np.zeros([640, 640], dtype=np.uint8)
cv2.polylines(im, [rect_r], 1, 255)
cv2.polylines(im, [rect_2], 1, 255)
plt.imshow(im)
plt.show()