密集人群标注、实现跟shanghaitech数据集同样格式

只能实现单张照片标记,无循环功能,日后改进

import  matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

import numpy as np
from scipy.io import savemat
from PIL import Image

# 加载图像
def load_image(path):
    return np.array(Image.open(path))

# 初始化坐标列表
coordinates = []

# 鼠标点击事件处理函数
def onclick(event):
    ix, iy = event.xdata, event.ydata
    coordinates.append([ix, iy])
    print(f'在x={ix}, y={iy}处标记点')

    # 可选:动态地在图上标记点
    ax.plot(ix, iy, 'ro')
    fig.canvas.draw()

# 图像路径
image_path = r'F:\crowd_data_self\img_6.jpg'
img = load_image(image_path)

fig, ax = plt.subplots()
ax.imshow(img)
cid = fig.canvas.mpl_connect('button_press_event', onclick)

plt.show()

# 关闭绘图窗口后
# 准备.mat文件数据结构
mat_data = {
    '__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Sat Oct 24 00:00:31 2015',
    '__version__': '1.0',
    '__globals__': [],
    'image_info': np.array([[(np.array(coordinates), np.array([[len(coordinates)]], dtype=np.uint8))]],
                           dtype=[('location', 'O'), ('number', 'O')])
}

# 保存为.mat文件
savemat('img_6.mat', mat_data)
print("数据已保存到'img_6.mat'")

存档供自我学习

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值