将一个文件夹下面的图像和对应的pts读进来,然后把pts文件里面的数据读入一个数组,然后画到图像上:

# -*- coding:utf- -*-

"""

测试数据样例

"""
import os
import cv2 list_dir = [
"/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM/001/",
"/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM/002/",
"/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM/003/",
"/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM/004/",
"/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM/005/"
] def readLmk(fileName):
landmarks = []
if not os.path.exists(fileName):
return landmarks
else:
fp = open(fileName)
i =
for line in fp.xreadlines():
#print line.strip("\n")
TT = line.strip("\n")
if i> and i<:
# print TT
TT_temp = TT.split(" ")
x = int(float(TT_temp[]))
y = int(float(TT_temp[].strip("\r")))
landmarks.append((x,y))
i +=
return landmarks def main():
for temp in list_dir:
for dirpath,dirnames,filenames in os.walk(temp):
for file in filenames:
if file.split('.')[] not in ['jpg','png']:
continue
print file
fullpath = os.path.join(temp,file)
ptsFile = temp + ""+file.split('.')[] + ".pts" # 读取图片
image = cv2.imread(fullpath)
# 读取对应的pts文件
landmarks = readLmk(ptsFile)
for point in landmarks: cv2.circle(image,point,,(,,)) width = image.shape[]
height = image.shape[]
print (width,height)
if width > :
# 归一化到1000
image = cv2.resize(image,(,height*/width)) cv2.imshow("WW",image)
cv2.waitKey()
input = raw_input('请输入: ')
if input == " ":
print ("copy正确的数据源")
newpath="/Users/anitafang/Downloads/Datasets/jiaozheng/2017sdm/SDM2/001/" cmd = "cp " + fullpath + " " + ptsFile+ " "+ newpath print cmd
os.system(cmd) if __name__ == '__main__':
main()

讲一下Python按行读取文件内容:

 filename = "/Users/anitafang/Downloads/Datasets/jiaozheng/annot/sdm/001/annot/"+cnt+".pts"

        f1 = open(filename)
print(filename)
line_nu =
for line in f1.xreadlines():
if line_nu > and line_nu<:
# print(line)
linestr = line.strip()
# print(linestr)
linestrlist = linestr.split("\t")
# print(linestrlist)
# linelist = [int(i) for i in linestrlist]
# print(linelist) line_nu +=

Python 读取数据的更多相关文章

  1. 其它课程中的python---6、python读取数据

    其它课程中的python---6.python读取数据 一.总结 一句话总结: 记常用和特例:慢慢慢慢的就熟了,不用太着急,慢慢来 库的使用都很简单:就是库的常用函数就这几个,后面用的时候学都来得及. ...

  2. python读取数据文件:pandas包详解

    本文转载自https://blog.csdn.net/brucewong0516/article/details/79092579 pandas包是一个高效的文件读取工具,适用于txt,excel,等 ...

  3. python读取数据写入excel的四种操作

    Python对Excel的读写主要有:xlrd.xlwt.xlutils.openpyxl.xlsxwriter几种 xlutils结合xlrd: 操作的是以xls后缀的excel,读取文件保留原格式 ...

  4. python读取数据

    #读取一行数据,去掉头尾空格 line = sys.stdin.readline().strip() #line类型为字符串 #字符串变成列表 line = sys.stdin.readline(). ...

  5. python读取数据写入excel

    '''写入excel文件''' import xlsxwriter # todo 创建excel文件 xl = xlsxwriter.Workbook(r'D:\testfile\test.xlsx' ...

  6. mysql timestamp为0值时,python读取后的对象为None

    MySQL数据表中,如果timestamp类型的字段,值为0, python从数据库读取数据后,得到对象是什么类型,是否为None呢? 下面来测试下. 创建数据表 首先创建数据表,其中字段pr_rul ...

  7. Python中数据的保存和读取

    在科学计算的过程中,往往需要保存一些数据,也经常需要把保存的这些数据加载到程序中,在 Matlab 中我们可以用 save 和 lood 函数很方便的实现.类似的在 Python 中,我们可以用 nu ...

  8. [转] Windows下使用Python读取Excel表格数据

    http://www.python-excel.org/这个网站罗列了很多关于在Python下操作Excel文件的信息,这里选择了其介绍的第一个模块xlrd . xlrd 0.9.2版本跨平台同时支持 ...

  9. Python读取Excel数据并根据列名取值

    一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...

随机推荐

  1. Spring Boot修改内置Tomcat端口号

    spring Boot 内置Tomcat默认端口号为8080,在开发多个应用调试时很不方便,本文介绍了修改 Spring Boot内置Tomcat端口号的方法. 一.EmbeddedServletCo ...

  2. 【转】UML类图符号 6种关系说明以及举例

    转自http://www.cnblogs.com/duanxz/archive/2012/06/13/2547801.html UML中描述对象和类之间相互关系的方式包括:依赖(Dependency) ...

  3. android 中 viewpager 滑动的指示器

    先看下效果图: 这个需要用到1个开源的 库,这个后面也会说下的. 工程目录: 1. MainActivity.java public class MainActivity extends Fragme ...

  4. 小程序踩过的一个小坑---解析二维码decodeURIComponent() url解码

    因为我们需要用户扫码进入小程序,每一个货柜都有一个对应的二维码,当然每个二维码里的信息也不一样.用户扫码进入小程序之后,二维码的信息会以参数q带进去,而我们只能在onLoad事件中拿到这个参数, 但是 ...

  5. Mac OSX 快捷键&命令行

    一.Mac OSX 快捷键 ctrl+shift                                    快速放大dock的图标会暂时放大,而如果你开启了dock放大Command+Op ...

  6. Android 源码阅读笔记

    Zygote: .Zygote 是系统启动之后创建的第二个进程2.Zygote 创建zygote Socket.虚拟机3.Zygote 在虚拟机中通过forkSystemServer, 创建Serve ...

  7. 使用Karma、Mocha实现vue单元测试

    Karma Karma是一个基于Node.js的JavaScript测试执行过程管理工具(Test Runner).该工具在Vue中的主要作用是将项目运行在各种主流Web浏览器进行测试.换句话说,它是 ...

  8. 多个inputstream的情况下,watermark的值怎么赋值? kakfa中多个partition提取 watermark

    1,org.apache.flink.streaming.api.operators; AbstractStreamOperator public void processWatermark1(Wat ...

  9. performance Counter

    Logman https://technet.microsoft.com/en-us/library/bb490956.aspx http://blogs.technet.com/b/askperf/ ...

  10. [Windows Azure] Guidelines for Connecting to Windows Azure SQL Database

    Guidelines for Connecting to Windows Azure SQL Database 6 out of 12 rated this helpful - Rate this t ...