draw rectangle with CV2

16 篇文章 2 订阅
11 篇文章 0 订阅
import os
import cv2
import numpy as np
import glob
import random

image_path = '/wgb_tensorflow/tfapi_vrep_detection531/11/1515530110_ang-55.png'
neg_path = '/wgb_tensorflow/tfapi_vrep_detection531/11/1515530110_ang-55_neg.txt'
obbs_path = '/wgb_tensorflow/tfapi_vrep_detection531/11/1515530110_ang-55_obbbs.txt'
pos_path = '/wgb_tensorflow/tfapi_vrep_detection531/11/1515530110_ang-55_pos.txt'

save_image = cv2.imread(image_path)
neg_f = open(neg_path)
neg_read = neg_f.readline()
i = 0
neg_points = []
while neg_read:
    i = i+1
    neg_read = neg_f.readline()
    if i>5:
        neg_points.append(neg_read)

neg_p = [];neg_ps =[]
i = 0
for point in neg_points:
    i +=1
    f =point.split(',')
    if len(f)>1:
        p = (int(point.split(',')[0]),int(point.split(',')[1]))
        neg_p.append(p)
        if i%4.0 ==0:
            neg_ps.append(neg_p)
            neg_p = []


pos_f = open(pos_path)
pos_read = pos_f.readline()
pos_points = []
i = 0
while pos_read:
    i = i+1
    pos_read = pos_f.readline()
    if i>5:
        pos_points.append(pos_read)

pos_p = [];pos_ps =[]
i = 0
for point in pos_points:
    i +=1
    f =point.split(',')
    if len(f)>1:
        p = (int(point.split(',')[0]),int(point.split(',')[1]))
        pos_p.append(p)
        if i%4.0 ==0:
            pos_ps.append(pos_p)
            pos_p = []


obbs_f = open(obbs_path)
obbs_read = obbs_f.readline()
obbs_points = []
while obbs_read:
    i = i+1
    obbs_read = obbs_f.readline()
    if i>5:
        obbs_points.append(obbs_read)


points_draw = pos_ps
drawing_image_path = '/wgb_tensorflow/tfapi_vrep_detection531/11/pos.png'

for ppoint in points_draw:
    pp0 = (ppoint[0][1], ppoint[0][0])
    pp1 = (ppoint[1][1], ppoint[1][0])
    pp2 = (ppoint[2][1], ppoint[2][0])
    pp3 = (ppoint[3][1], ppoint[3][0])
    color1 = (0, 0, 255)  # red
    color2 = (100, 250, 100)  # green

    lineWidth = 2
    cv2.line(save_image, pp0, pp1, color1, lineWidth)
    cv2.line(save_image, pp1, pp2, color2, lineWidth)
    cv2.line(save_image, pp2, pp3, color1, lineWidth)
    cv2.line(save_image, pp3, pp0, color2, lineWidth)

cv2.imwrite(drawing_image_path, save_image)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值