根据点绘制边框 cv2

根据像素值快速获取下标

# get index
def get_index(im, value):
    # Load image
    im = cv2.imread('image.png')
    blue = [255, 0, 0]
    # Get X and Y coordinates of all blue pixels
    X, Y = np.where(np.all(im == value, axis=2))
    zipped = np.column_stack((X, Y))
    return zipped

根据坐标画图像的四边框

这里用的是x,y的最大值和最小值进行绘制
value是想需要找的图像的像素值

# get index
def arrow_index(im, value):
    # Load image
    # im = cv2.imread('image.png')
    # blue = [255, 0, 0]
    # Get X and Y coordinates of all blue pixels
    X, Y = np.where(np.all(im == value, axis=2))
    max_x = max(X)
    min_x = min(X)
    min_y = min(Y)
    max_y = max(Y)
    print(X, Y)
    color = (166, 166, 166)
    newBox = [[min_y, min_x], [max_y, min_x], [max_y, max_x], [min_y, max_x]]
    point = np.array(newBox).astype(int)
    cv2.line(im, tuple(point[0]), tuple(point[1]), color, thickness=1)
    cv2.line(im, tuple(point[1]), tuple(point[2]), color, thickness=1)
    cv2.line(im, tuple(point[2]), tuple(point[3]), color, thickness=1)
    cv2.line(im, tuple(point[3]), tuple(point[0]), color, thickness=1)
    cv2.imwrite('./result.jpg', img=im)
    print()
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值