使用cv2在图片上绘制点

数据的格式为坐标构成的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")

 

  • 9
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值