京东金融大数据竞赛猪脸识别(1)-从视频提取图像
2018-03-13 10:35
656 查看
2017年11月的京东金融大数据竞赛参与人数最多的是猪脸识别的算法比赛,参加整个大数据比赛的有四千多人,而猪脸识别算法组就有一千多人。可见,搞图像识别的的人很多啊。想要提升自己价值的小伙伴们,向语音、文本、机器人等领域进发吧,有了机器学习的基础,入门这些领域应该都不是太难。
比赛给的数据是30头猪的视频,做识别的第一步还是从视频中去图像吧。本想用以前写过的视频取帧程序。看Matlab示例的时候发现用Matlab取帧更简便易行,那就用它吧。这样又省了很多时间。代码如下:
该程序运行完后,就得到了30头猪的图像信息。若需增加数据量,可将提取帧的间隔减小。
比赛给的数据是30头猪的视频,做识别的第一步还是从视频中去图像吧。本想用以前写过的视频取帧程序。看Matlab示例的时候发现用Matlab取帧更简便易行,那就用它吧。这样又省了很多时间。代码如下:
%exam1.m extract frame from video clc; close all; imtool close all; clear; %30段视频在本代码同级目录video文件夹下,格式为mp4 fpath = [pwd,'\video\*.mp4']; fname = dir(fpath); fnum = numel(fname); vidpath = [pwd,'\video']; try for i=1:fnum videoname = fullfile(vidpath,fname(i).name); %读取视频数据 videoObject = VideoReader(videoname); % 获取视频中帧数. numberOfFrames = videoObject.NumberOfFrames; vidHeight = videoObject.Height; vidWidth = videoObject.Width; numberOfFramesWritten = 0; figure; writeToDisk = true; %对视频文件全路径进行分离. [folder, baseFileName, extentions] = fileparts(videoname); %获取当前路径 folder = pwd; %在当前路径下建立子文件夹image,并在image下为各视频建立以文件名命名的子文件夹,用以存放该视频提取的帧 outputFolder = sprintf('%s/image/%s', folder, baseFileName); if ~exist(outputFolder, 'dir') mkdir(outputFolder); end %每分钟约为30帧图像,每隔15帧取一帧 for frame = 1 :15: numberOfFrames %读取帧数据 thisFrame = read(videoObject, frame); image(thisFrame); caption = sprintf('Frame %4d of %d.', frame, numberOfFrames); title(caption, 'FontSize', fontSize); drawnow; % Force it to refresh the window. %将图像帧数据写入文件 if writeToDisk % 创建图像名,格式为“视频名-帧序号” imgName = sprintf('%s-%04d.jpg',baseFileName, frame); outputFullFileName = fullfile(outputFolder, imgName); text(5, 15, imgName, 'FontSize', 20); % Extract the image with the text "burned into" it. frameWithText = getframe(gca); . imwrite(frameWithText.cdata, outputFullFileName, 'jpg'); end % 输出提取信息. if writeToDisk progressIndication = sprintf('Wrote frame %4d of %d.', frame, numberOfFrames); else progressIndication = sprintf('Processed frame %4d of %d.', frame, numberOfFrames); end disp(progressIndication); numberOfFramesWritten = numberOfFramesWritten + 1; end end catch warning('Problem using function. Assigning a value of 0.'); a = 0; end
该程序运行完后,就得到了30头猪的图像信息。若需增加数据量,可将提取帧的间隔减小。
相关文章推荐
- 京东金融大数据竞赛猪脸识别(3)- 图像特征提取之二
- 京东金融大数据竞赛猪脸识别(2)- 图像特征提取之一
- 京东金融大数据竞赛猪脸识别(5)- 识别方法之一
- 京东金融大数据竞赛猪脸识别(6)- 识别方法之二
- 京东金融大数据竞赛猪脸识别(7)- 识别方法之三
- 京东金融大数据竞赛猪脸识别(4)-方法选取
- 京东金融大数据竞赛猪脸识别(9)- 识别方法之五
- 京东金融大数据竞赛猪脸识别(8)- 识别方法之四
- 模式识别之线条矩形识别---长方形画布或纸张并提取图像内容
- 京东猪脸识别比赛数据预处理:用Python将视频每一帧提取存储为图片
- ffmpeg tutorial01--------提取视频图像
- 我是如何快速拿下datacastle图像识别竞赛“猫狗大战”冠军的 | 含全代码和详细说明
- 我收集的一些目标检测、跟踪、识别标准测试视频集和图像数据库
- ffmpeg tutorial01--------提取视频图像
- MATLAB中对视频进行提取图像
- 【转载】目标检测、跟踪、识别标准测试视频集和图像数据库
- 视频图像识别学习系列:线结构光三维测量重建
- ffmpeg tutorial01--------提取视频图像
- 目标检测、跟踪、识别标准测试视频集和图像数据库
- 如何使用matlab从视频中提取出一帧帧图像