python脚本实现给定标注bbox,landmark在原图中显示人脸框,人脸关键点

程序功能简介:

利用给定的标注bbox,landmark在原图中显示人脸框,人脸关键点:


给定标注txt文件数据格式,如下图所示:


lfw_5590\Aaron_Eckhart_0001.jpg 84 161 92 169 106.250000 107.750000 146.750000 112.250000 125.250000 142.750000 105.250000 157.750000 139.750000 161.750000
lfw_5590\Aaron_Guiel_0001.jpg 85 172 93 181 100.250000 111.250000 145.750000 116.750000 124.250000 136.750000 92.750000 159.750000 138.750000 163.750000
lfw_5590\Aaron_Peirsol_0001.jpg 88 173 94 179 106.750000 113.250000 146.750000 113.250000 129.250000 139.750000 108.250000 153.250000 146.750000 152.750000
lfw_5590\Aaron_Pena_0001.jpg 67 176 83 192 101.750000 116.750000 145.250000 103.750000 125.250000 136.750000 119.750000 163.750000 146.250000 155.750000
lfw_5590\Aaron_Sorkin_0001.jpg 73 164 86 178 101.250000 112.250000 143.750000 111.750000 129.750000 137.750000 99.250000 155.250000 142.250000 154.750000
lfw_5590\Aaron_Tippin_0001.jpg 77 165 90 177 103.750000 111.750000 141.750000 111.250000 129.250000 133.750000 110.750000 156.250000 134.750000 155.250000
lfw_5590\Abba_Eban_0001.jpg 80 164 90 175 105.750000 113.750000 145.750000 110.250000 133.750000 136.250000 107.750000 156.250000 148.750000 155.250000
lfw_5590\Abdel_Aziz_Al-Hakim_0001.jpg 86 169 90 173 110.750000 110.250000 148.250000 113.750000 136.750000 133.250000 111.750000 152.250000 141.750000 154.250000
lfw_5590\Abdel_Nasser_Assidi_0001.jpg 80 167 87 174 103.750000 112.250000 148.250000 115.250000 124.250000 134.250000 106.750000 155.750000 136.250000 159.250000
lfw_5590\Abdulaziz_Kamilov_0001.jpg 76 162 90 177 108.250000 110.250000 146.750000 116.250000 128.750000 137.750000 104.250000 152.750000 133.250000 158.250000

python脚本如下:


#!/usr/bin/env python2.7
# coding: utf-8
#第一行用于指定编译器位置,先在环境变量中查找python编译器; 第二行申明中文文件编码的注释

import cv2

annot_dir = '/home/xiao/code/deep-landmark/dataset/train'

def join(str1, str2):
    str = str1 + '/' + str2
    return str


# 判断这是否为一个主程序,其他python程序无法调用
if __name__ == '__main__':

    txt = join(annot_dir, 'trainImageList.txt')
    with open(txt, 'r') as fd:
        lines = fd.readlines()

    i=0
    for line in lines:
        i=i+1
        print i
        line = line.strip()
        components = line.split(' ')
        img_path =  join(annot_dir, components[0].replace('\\','/'))
        img = cv2.imread(img_path, -1)
        cv2.rectangle(img, (int(components[1]),int(components[3])), (int(components[2]),int(components[4])), (0,0,255), 2)
        # 强制类型转换,从string转换为float,再转换为int
        cv2.circle(img, (int(float(components[5])),int(float(components[6]))), 2, (0,255,0), -1)
        cv2.circle(img, (int(float(components[7])),int(float(components[8]))), 2, (0,255,0), -1)
        cv2.circle(img, (int(float(components[9])),int(float(components[10]))), 2, (0,255,0), -1)
        cv2.circle(img, (int(float(components[11])),int(float(components[12]))), 2, (0,255,0), -1)
        cv2.circle(img, (int(float(components[13])),int(float(components[14]))), 2, (0,255,0), -1)
        cv2.imshow('image',img)
        cv2.waitKey(1000)



  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值