检测视频文件中的面部。使用数据类型时出错

时间:2017-04-09 11:53:35

标签: matlab viola-jones

我有以下问题。 我正在使用matlab 2016。 我想使用Viola-Jones算法检测视频文件中的面部。 当我尝试在step语句中输入视频文件时,出现以下错误:

Error using
   vision.CascadeObjectDetector/validateInputsImpl
   (line 330)
   Expected input number 2 to be
   one of these types:

   uint8, uint16, double, single,int16

   Instead its type was
   vision.VideoFileReader.

   Error in VJ1_video (line 12)
   bboxes = step(faceDetector, videoFReader);

我知道应该将VideoFileReader的类型转换为以下类型之一:uint8,uint16,double,single,int16。 但我不明白如何做到这一点。请告诉我。 这是我的程序代码:

clear all;
%Load the video using a video reader object
  videoFReader = vision.VideoFileReader('D:\465.avi');
%Create a detector object.
  faceDetector = vision.CascadeObjectDetector;
%Detect faces.
  bboxes = step(faceDetector, videoFReader);
%Annotate detected faces
  IFaces = insertObjectAnnotation(videoFReader, 'rectangle', bboxes, 'Лицо');
%Create a video player object to play the video file.
  videoPlayer = vision.VideoPlayer;

%Use a while loop to read and play the video frames.
  while ~isDone(videoFReader)
    videoFrame = videoFReader();
    videoPlayer(videoFrame);
  end
%Release the objects.
  release(videoPlayer);
  release(videoFReader);

1 个答案:

答案 0 :(得分:0)

CascadeObjectDetector适用于单帧(图像),而不适用于帧序列(视频)。因此,正如您已经建议的那样,step函数的输入是图像。更改代码,以便在迭代帧时进行面部检测。

(未经测试的)建议:

    %Load the video using a video reader object
      videoFReader = vision.VideoFileReader('D:\465.avi');
    %Create a video player object to play the video file.
      videoPlayer = vision.VideoPlayer;
    %Create a detector object.
      faceDetector = vision.CascadeObjectDetector;

    %Use a while loop to read and play the video frames.
      while ~isDone(videoFReader)
        videoFrame = videoFReader();
        %Detect faces.
        bboxes = step(faceDetector, videoFReader);
        %Annotate detected faces
        IFaces = insertObjectAnnotation(videoFReader, 'rectangle', bboxes, 'Лицо');
        %Show annotated frames IFaces (instead of videoFrame)
        videoPlayer(IFaces);
      end

    %Release the objects.
      release(videoPlayer);
      release(videoFReader);