小图检测数据处理删除边缘小框

import cv2
import xml.etree.ElementTree as ET
import pdb
import os


# path_ori="/home/huangs/00-Projects/FruitsRecognition/DataSet/MakingDataSet/100fruits/phoneShot4/img/"
# xml_fold = '/home/huangs/00-Projects/FruitsRecognition/DataSet/MakingDataSet/100fruits/phoneShot4/annotation/'
# path_new = '/home/huangs/00-Projects/FruitsRecognition/DataSet/MakingDataSet/100fruits/phoneShot4/imgsmall/'


path_ori="/home/hs/data/yili/images/"
xml_fold = '/home/hs/data/yili/annotations/'
path_new = '/home/hs/data/yili/imgs0/'
imgslist = os.listdir(path_ori)
numy = 0
numx = 0
for img in imgslist:                  #20200313080026_jx004_0.jpg
    print(img)
    jpg_file = img.strip()         #20200313080026_jx004_0.jpg
    jpg_id = jpg_file.split('.')[0]  #20200313080026_jx004_0
    xml_file = jpg_id + '.xml'        #20200313080026_jx004_0.xml
    image = cv2.imread(path_ori + img, -1)
    height_origin, width_origin = image.shape[:2]

    xml_file = os.path.join(xml_fold, xml_file)
    if os.path.exists(xml_file):

        updateTree = ET.parse(xml_file)
        root = updateTree.getroot()

        element_object = root.findall('object')
        print(image.shape)
        for i in range(len(element_object)):
            xmin = element_object[i].find('bndbox').find('xmin').text
            xmax = element_object[i].find('bndbox').find('xmax').text
            ymin = element_object[i].find('bndbox').find('ymin').text
            ymax = element_object[i].find('bndbox').find('ymax').text

            smallimg = image[int(float(ymin)):int(float(ymax)), int(float(xmin)):int(float(xmax))]
            position = [int(float(xmin)), int(float(xmax)), int(float(ymin)), int(float(ymax))]
            h=smallimg.shape[0]
            w=smallimg.shape[1]
            if h*w>20:
                smallimg_path = path_new + jpg_id
                #cv2.imwrite(new_jpg_file, cropped)
                cv2.imwrite(smallimg_path +"_"+str(i)+".jpg",smallimg)
            else:
                print(position)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值