数据的格式为坐标构成的list,要将这些点绘制在图片上并保存:
import os
import sys
import cv2
imagePath="./img/"
image = cv2.imread(imagePath+"1.jpg")
point_size = 1
point_color = (0, 0, 255) # BGR
thickness = 4 # 0 、4、8
# 此处省略得到坐标的过程,coordinates存放坐标
# 格式为:coordinates=[[x1,y1],[x2,y2],[x3,y3],...,[xn,yn]]
for coor in coordinates:
print(coor)
cv2.circle(image, (int(coor[0]),int(coor[1])), point_size, point_color, thickness)
cv2.imwrite('1.png', image, [int(cv2.IMWRITE_JPEG_QUALITY),95])
2、常用代码段:从文件夹下读取文件名:
imagePath="./img/"
files = os.listdir(imagePath)
for file in files:
print(file)
3、常用文件命处理函数:replace('','')
例如文件命为:AAA_1.jpg,要提取出1:
file="AAA_1.jpg"
fileName = file.replace('IMG_','')
fileName = fileName.replace('.jpg','')
print(fileName)
4、读取.mat文件:
from scipy.io import loadmat
groundPath="./ground_truth/"
m=loadmat(groundPath+"GT_IMG_"+fileName+".mat")