Crowd counting的数据集包括两部分:图像部分和标签部分

标签部分主要包括每个人头的坐标点:(x, y);

常见的标签格式例如:ShanghaiTech数据集中的格式,用mat文件存储每个人头的坐标点,一张图像对应一个mat文件;

当我们自己制作数据集时,需要经历以下几个步骤:

1)拍摄图像或者视频;视频需要切分成帧;

2)在图像上进行标点,标点的同时会记录下坐标点;

3)根据这些坐标点生成每张图像对应的.mat文件;

4)在训练时,将mat文件中的坐标转换为density map;

以下是每个步骤中所需要用到的py文件:

1)拍摄图像,如果是视频的话需要切分为视频帧:

将视频切分为视频帧:

import imageiofilename = "E:\video.MP4"
vid = imageio.get_reader(filename, 'ffmpeg')try:for num, im in enumerate(vid):if (num / 50) and (num % 50) == 0:    # 控制图像的输出张数;imageio.imwrite('E:\save_photo_from_video\{}.jpg'.format(num // 50), im)else:continue
except imageio.core.format.CannotReadFrameError or RuntimeError:pass

2)在图像上进行标注:

有一些现有的工具也可以完成相应的操作,这里我们用一段py代码来实现在图像上打点并将图像上人头的坐标点写入txt文件中,已备下一步使用:

打点代码:

import cv2
import os"""
This code is used to:
1)对图片进行标注
2)生成对应的包含坐标信息的.txt文件
"""imgs_path = "E:/images/" # 存放图像的文件夹
txt_path = "E:/txt/" # 存放txt文件的文件夹
files = os.listdir(imgs_path)
img = 0
coordinates = []def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):if event == cv2.EVENT_LBUTTONDOWN:cv2.circle(img, (x, y), 4, (0, 255, 0), thickness=-1)coordinates.append([x, y])print([x,y])cv2.imshow("image", img)for file in files:  # for i in range(80, len(files)):coordinates = []img = cv2.imread(imgs_path+file)cv2.namedWindow("image")cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)cv2.imshow("image", img)cv2.waitKey(0)with open(txt_path+file.replace("jpg","txt"), "w+") as f:for coor in coordinates:f.write(str(coor[0])+" "+str(coor[1])+"\n")    # 记录每个人头的坐标点f.write(str(len(coordinates)))    # 记录一张图像中的人头总数print(file+" is ok !"+"\n")

使用这个打点代码时,点击运行,会出现第一张图像,然后用鼠标在上面打点,标注完一张图像后,点击右上角的×关闭这张图像,开始对第二张图像打点,直到所有图像结束;

如果中途有图像发现点错了,可以记录下错误的图像名称,待全部点完之后再进行处理;如果图像太多,一次性标注不完,建议分批进行处理;

以上就是名为0.jpg的图像打点的过程以及生成对应的0.txt,第三张图可以看到txt中的内容,为人头的坐标,最后一行为人头总数;

3)通过这些txt文件中的坐标点,形成mat文件;(注:使用ShanghaiTech数据集中的同样的格式)

将txt文件转换为mat文件:

import numpy as np
import scipy.io as io
import ostxt_path = "E:/txts/"
save_path = "E:/mats/"
files = os.listdir(txt_path)
for file in files:print(file)with open(txt_path+file, "r") as f:datas = f.readlines()list = []for i in range(0, len(datas) - 1):line = datas[i].strip('\n')ele = line.split( )list.append(ele)data_length = np.array([[datas[len(datas) - 1]]], dtype=np.uint8)data = np.array(list, dtype=np.float64)dt = np.dtype([('location', np.ndarray), ('number', np.ndarray)])data_combine = np.array([(data, data_length)], dtype=dt)image_info = np.array([data_combine], dtype=[('location', 'O'),('number', 'O')])   # [[(data, data_length)]]image_info = np.array([[image_info]], dtype=object)__header__ = b'MATLAB 5.0 MAT-file Platform: nt, Created on: 2021'__version__ = '1.0'__globals__ = '[]'dict = {'__header__': __header__, '__version__': __version__, '__globals__': __globals__, 'image_info':image_info}gt = dict["image_info"][0,0][0,0][0]io.savemat(save_path+file.replace("txt","mat"), dict)

通过这个步骤,我们就可以得到每张图像对应的mat文件;

4)根据mat文件制作训练时需要的density map

此处使用matlab进行实现:

a)preapre_World_10.m

clc; clear all;fileFolder=fullfile('F:\label');
dirOutput=dir(fullfile(fileFolder,'*'));
fileNames={dirOutput.name}';standard_size = [384,512]; # 可以修改大小dataset_name = ['WorldExpo10'];
original_path = ['F:/dataset/'];
output_path = 'F:/data/';
att = 'test';
train_path_img = strcat(output_path, 'train_frame/');
mkdir(train_path_img);for ii = 3:105gt_path = ['F:/train_label/' fileNames{ii} '/'];train_path_den = strcat(output_path, 'train_lable/', fileNames{ii}, '/');mkdir(train_path_den);matFolder=fullfile(gt_path);matdirOutput=dir(fullfile(matFolder,'*'));matNames={matdirOutput.name}';num_images=length(matdirOutput)-1;disp(num_images)for idx = 3:num_imagesi = idx;if (mod(idx,10)==0)fprintf(1,'Processing %3d/%d files\n', idx, num_images);endload(strcat(gt_path, matNames{idx}));input_img_name = strcat(original_path,'train_frame/',strrep(matNames{idx}, 'mat', 'jpg'));disp(input_img_name)im = imread(input_img_name);[h, w, c] = size(im);annPoints =  point_position;rate_h = standard_size(1)/h;rate_w = standard_size(2)/w;im = imresize(im,[standard_size(1),standard_size(2)]);annPoints(:,1) = annPoints(:,1)*double(rate_w);annPoints(:,2) = annPoints(:,2)*double(rate_h);im_density = get_density_map_gaussian(im,annPoints); im_density = im_density(:,:,1);imwrite(im, [output_path 'train_frame/' strrep(matNames{idx}, 'mat', 'jpg')]);csvwrite([output_path 'train_lable/' fileNames{ii} '/' strrep(matNames{idx}, 'mat', 'csv')], im_density);end
end

b)get_density_map_gaussian()实现:

function im_density = get_density_map_gaussian(im,points)im_density = zeros(size(im));
[h,w] = size(im_density);if(length(points)==0)return;
endif(length(points(:,1))==1)x1 = max(1,min(w,round(points(1,1))));y1 = max(1,min(h,round(points(1,2))));im_density(y1,x1) = 255;return;
end
for j = 1:length(points)   f_sz = 15;sigma = 4.0;H = fspecial('Gaussian',[f_sz, f_sz],sigma);x = min(w,max(1,abs(int32(floor(points(j,1)))))); y = min(h,max(1,abs(int32(floor(points(j,2))))));if(x > w || y > h)continue;endx1 = x - int32(floor(f_sz/2)); y1 = y - int32(floor(f_sz/2));x2 = x + int32(floor(f_sz/2)); y2 = y + int32(floor(f_sz/2));dfx1 = 0; dfy1 = 0; dfx2 = 0; dfy2 = 0;change_H = false;if(x1 < 1)dfx1 = abs(x1)+1;x1 = 1;change_H = true;endif(y1 < 1)dfy1 = abs(y1)+1;y1 = 1;change_H = true;endif(x2 > w)dfx2 = x2 - w;x2 = w;change_H = true;endif(y2 > h)dfy2 = y2 - h;y2 = h;change_H = true;endx1h = 1+dfx1; y1h = 1+dfy1; x2h = f_sz - dfx2; y2h = f_sz - dfy2;if (change_H == true)H =  fspecial('Gaussian',[double(y2h-y1h+1), double(x2h-x1h+1)],sigma);endim_density(y1:y2,x1:x2) = im_density(y1:y2,x1:x2) +  H;endend

至此,自己制作crowd counting数据集完毕。

自己制作crowd counting数据集相关推荐

  1. 人群计数数据集汇总和详细介绍,全网最全,crowd counting datasets

    Crowd Counting数据集汇总 视频监控=video surveillance https://github.com/gjy3035/Awesome-Crowd-Counting/blob/m ...

  2. 人流密度(crowd counting)估计方法

    人流密度估计方法在深度学习起来之前主要有两种,直接估计和间接估计.近两年又有几篇做的不错的是使用cnn来进行估计. 面临的挑战 要进行准确的人流密度估计,面临了如下的难点 1.低分辨率:可以看看UCF ...

  3. crowd counting 常用数据集 百度网盘

    Crowd counting 常用数据集及下载地址: 包括: ShanghaiTech 数据集 UCF_CC_50 数据集 World 10 数据集 Mall 数据集 USCD 数据集 百度网盘下载地 ...

  4. 人群计数(Crowd Counting)研究综述

    52CV曾经报道过两篇关于人群计数的新出论文(可在精华文章汇总中找到),皆获得不少关注,今天的文章来自复旦大学计算机的在读博士老田和电闪雷鸣为我们介绍人群计数的相关技术和进展,想对此方向有更全面把握的 ...

  5. Crowd Counting领域论文阅读

    CrowdNet: A Deep Convolutional Network for Dense Crowd Counting  本文使用 deep and shallow, fully convol ...

  6. Cross-scene Crowd Counting via Deep Convolutional Neural Networks2015论文笔记

    Absrtact 挑战:跨场景人群计数(目标场景无标注): 提出DCNN,由人群密度和人数交替训练: 提出data-driven方法微调CNN模型以适应目标场景: 提出包含108个场景(标注20000 ...

  7. 《Improved Crowd Counting Method Based onScale-Adaptive Convolutional Neural Network》论文笔记

    <Improved Crowd Counting Method Based onScale-Adaptive Convolutional Neural Network>论文笔记 论文地址 ...

  8. 在caffe 中添加Crowd counting 数据层

    #目录 [TOC] 一.简介 Crowd counting一般以人群图像作为输入,网络回归该图像对应的密度图.以往做法是先在matlab中根据图像的label(人头位置)生成密度图,然后将输入图像及密 ...

  9. 论文Depth Information Guided Crowd Counting for Complex Crowd Scenes

    Depth Information Guided Crowd Counting for Complex Crowd Scenes 摘要 出于城市安全的考虑,监控和分析人群拥挤事件是非常重要的.在一张拥 ...

最新文章

  1. Blender 和Unreal Engine中的模块化3D建筑技能学习视频教程
  2. 2019全球AI人才分布图:美国占44%,中国人才净流入
  3. serverless 框架_研发的未来在哪里?Serverless 云开发来了!
  4. 【Swift】UITableViewCell 中 TTTAttributedLabel 超链接无法点击的问题
  5. 皮一皮:秀恩爱死的快啊!!!!
  6. linux通过管道的进程通信,linux 线程或进程之间通过管道通信(pipe)
  7. VS可视化调试学习总结
  8. [WebKit] JavaScriptCore解析
  9. NoSQL和传统数据库的区别
  10. https://www.usb.org/
  11. This view is not constrained vertically: at runtime
  12. 5000字 大数据时代读书笔记_《大数据时代》读后感 读书笔记
  13. iOS-关于微信支付
  14. html5视频在线剪辑,五种剪辑方法让视频更精彩
  15. 测试计划测试用例及用例评审
  16. ue的xml格式转换_迷你档-迷你档(minidown)下载 v2.5官方版--pc6下载站
  17. 计算机命令窗口怎么打开,如何打开命令行窗口_教你在win7上直接打开命令行窗口 - 驱动管家...
  18. C语言_宏函数_换行符
  19. android文件管理器listview,浅析Android文件管理器(项目一)
  20. 卷积神经网络如何识别图像

热门文章

  1. mysql无法停止slave_遇到诡异的问题 stop slave 无法停止
  2. Oracle:UGA PGA
  3. 小学计算机网络教室上机制度,网络教室上机登记制度
  4. Python爬虫入门教程 63-100 Python字体反爬之一,没办法,这个必须写,反爬第3篇...
  5. HashMap原理浅析(关于红黑树是什么?)
  6. 计算机音乐数字乐谱星星点灯,郑智化歌曲《星星点灯》简谱
  7. 【动态规划】矩阵链乘法
  8. oracle两个表数据比较,oracle数据库两表数据比较
  9. 输出华氏 摄氏度转换表
  10. JS控制submit表单提交前进行预览和confirm确认提交