zoukankan      html  css  js  c++  java
  • python文件处理-将图像根据坐标画矩形标记

    内容涉及:文件遍历,选取csv后缀文件,用cv操作图片

    import csv
    import os
    import sys
    import numpy as np
    import copy
    import shutil
    import pandas as pd
    from collections import Counter
    from shutil import copyfile
    import cv2
    
    path = path = os.getcwd()
    path_1 = path + '/' + 'data_error_0813'
    list_name = os.listdir(path_1)
    for n in list_name:
        if n[-3:] == 'csv':
            csvpath = path_1 + '/' + n
            imgpath = path_1 + '/' + n[:-3] + 'JPG'
            print(imgpath)
            if not os.path.exists(imgpath):
                print("nothing")
    
            filehand = open(csvpath,'r')
            csvlist = filehand.readlines()
            mark = []
            image = []
            count = 1
    
    
            for m in csvlist[1:]:
                m_split = m.split(',')
                xy = [m_split[2], m_split[3]]
                mark.append(xy)
                image = cv2.imread(imgpath)
                print("type:",type(image))
                first_point = (int(m_split[2])-50,int(m_split[3])-50)
                last_point = (int(m_split[2])+50,int(m_split[3])+50)
                cv2.rectangle(image, first_point, last_point, (0,255,0),2)
                cv2.imwrite(imgpath,image)
                print("标记次数",count)
                count = count + 1
    
        else:
            continue
        print(mark)
  • 相关阅读:
    vs2005 enable your debug
    暑假的安排
    session
    我所看过的电影——不断更新中……
    symbian
    CUDA学习。。。visual assist 扩展
    MySQL密码修改
    fcitx in Fedora
    LDAP身份验证
    mysql自增auto_increment删除记录
  • 原文地址:https://www.cnblogs.com/niulang/p/11350566.html
Copyright © 2011-2022 走看看