Python 讀取資料

2022-03-24 02:22:45 字數 2953 閱讀 3694

將乙個資料夾下面的影象和對應的pts讀進來,然後把pts檔案裡面的資料讀入乙個陣列,然後畫到影象上:

# -*- coding:utf-8 -*-

"""測試資料樣例

"# 讀取

image =cv2.imread(fullpath)

# 讀取對應的pts檔案

landmarks =readlmk(ptsfile)

for point in

landmarks:

cv2.circle(image,point,

1,(255,0,0

)) width = image.shape[0

] height = image.shape[1

] print (width,height)

if width > 800

: # 歸一化到1000

image = cv2.resize(image,(800,height*800/width))

cv2.imshow("ww

",image)

cv2.waitkey(10)

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 = 1

for line in

f1.xreadlines():

if line_nu > 51 and line_nu<72

: # print(line)

linestr =line.strip()

# print(linestr)

linestrlist = linestr.split("\t"

) # print(linestrlist)

# linelist = [int(i) for i in

linestrlist]

# print(linelist)

line_nu += 1

Python 讀取資料

將乙個資料夾下面的影象和對應的pts讀進來,然後把pts檔案裡面的資料讀入乙個陣列,然後畫到影象上 coding utf 8 測試資料樣例 讀取 image cv2.imread fullpath 讀取對應的pts檔案 landmarks readlmk ptsfile for point in l...

python讀取hdfs資料

載入包from hdfs.client import client self.filename user hdfs read.txt 讀取hdfs檔案內容,將每行存入陣列返回def read hdfs file self with client.read samples.csv encoding u...

python 讀取mysql資料

import pymysql import pandas as pd defload data from mysql conn pymysql.connect host 127.0.0.1 port 3306 user test password test db database charset u...