使用 MATLAB 检测拥挤图像中的头部

Detection of heads in a crowded image using MATLAB

我目前正在 "Crowd count estimation" 使用 MATLAB 做一个项目。对于那个项目,我需要在拥挤的图像(使用航拍相机拍摄)中找到头部的数量。我目前正在使用圆形霍夫变换来检测图像中的头部。

头部大小随海拔高度而变化。因此,我以接受 (image,Min_head_size,Max_head_size) 作为参数的方式进行编码。头部大小将被视为圆的半径(圆形霍夫变换),并且将检测该半径的圆。我已将阈值设置为 (pi*radius)。

用上面的方法,我无法检测到所有的人头。还有很多误报。我可以这样进行吗?有没有其他解决方案可以精确计算人数?

    function Crowd_counter(img,r1,r2)

    img1 = imread(img);                       %read the image
    img=im2bw(img1,graythresh(img1));         %convert into binary
    imgBW = edge(img);                        %'canny' edge detection
    count=0;
    FDetect = vision.CascadeObjectDetector;    %for face detection
    BB = step(FDetect,img1);                   %bounding box for face detect

    for i=r1:r2
        [ydetect,xdetect,Accumulator] = houghcircle(imgBW,i,(i*pi)); %circular hough
        y{count+1}=ydetect;                     %storing y co-ordinates
        x{count+1}=xdetect;                     %storing x co-ordinates
        count=count+1;
        i=i+1;
    end

    disp(count);
    figure;
    imshow(img1);                          %for visualizing detected heads
    hold on;
    crowd=0;
    for j=1:count
        crowd=crowd+length(x{j});          %for counting detected heads
        plot(x{j},y{j},'.','LineWidth',2,'Color','red');
        j=j+1;
    end

    disp('Number of heads:');
    disp(crowd);
    disp('Number of faces:');
    disp(size(BB,1));
    disp('Total');
    disp(crowd+size(BB,1));

Input image

Output from Crowd_counter('51.jpg',3,7)

好吧,这似乎是一个不错的方法。我没有对此进行过试验,但从您的输出图像来看,似乎很多边缘都被错误分类为头部。我的第一个想法是使用 Hessian 矩阵,就像在 HARRIS corner detector 的后续步骤中使用的那样可以帮助消除其中的一些。这应该消除一些误报。我想弄清楚如何找到假阴性将需要更多的努力。我想再次强调,我自己并没有尝试过这个,只有当你觉得逻辑对你有意义时才走这条路。