Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我如何在图像/视频中找到一个知道其真实物理尺寸的对象?_C++_Matlab_Image Processing - Fatal编程技术网

C++ 我如何在图像/视频中找到一个知道其真实物理尺寸的对象?

C++ 我如何在图像/视频中找到一个知道其真实物理尺寸的对象?,c++,matlab,image-processing,C++,Matlab,Image Processing,我有一个图像样本,希望检测图像/视频中的对象以及其他已经提前知道该对象真实物理尺寸的对象。我有一个图像样本(它的飞机门),我想找到飞机门上的窗口,知道它的物理尺寸(我们说它的内径是20cm,外径是23cm)和它在门上的真实位置(例如它到门框的最小距离是15cm)。我还可以事先知道我的相机分辨率。任何MATLAB代码或OpenCV C++都可以自动处理图像处理? 这是我的图片样本 以及更复杂的圆形徽标图像。 我运行了第二个复杂图像的代码,但没有得到相同的结果。这是图像结果。 我不会太担心精确的

我有一个图像样本,希望检测图像/视频中的对象以及其他已经提前知道该对象真实物理尺寸的对象。我有一个图像样本(它的飞机门),我想找到飞机门上的窗口,知道它的物理尺寸(我们说它的内径是20cm,外径是23cm)和它在门上的真实位置(例如它到门框的最小距离是15cm)。我还可以事先知道我的相机分辨率。任何MATLAB代码或OpenCV C++都可以自动处理图像处理? 这是我的图片样本

以及更复杂的圆形徽标图像。

我运行了第二个复杂图像的代码,但没有得到相同的结果。这是图像结果。

我不会太担心精确的几何结构和校准,而是根据窗口自身的特性来找到窗口

二值化效果相对较好,无论是在整个图像上还是在感兴趣的大区域中

然后,可以根据近似面积和/或圆度选择最可能的水滴


您正在图像中寻找一个圆,因此我建议您使用Hough圆变换

  • 将图像转换为灰色
  • 在图像中查找边
  • 使用Hugh circle transform在图像中查找圆
  • 对于每个候选圆,对圆的值进行采样,如果这些值对应于预定义的值,则接受 守则:

    clear all
    
    % Parameters
    minValueWindow = 90;
    maxValueWindow = 110;
    
    % Read file
    I = imread('image1.jpg');
    Igray = rgb2gray(I);
    [row,col] = size(Igray);
    
    % Edge detection
    Iedge = edge(Igray,'canny',[0 0.3]);
    
    % Hough circle transform
    rad = 40:80; % The approximate radius in pixels
    detectedCircle = {};
    detectedCircleIndex = 1;
    for radIndex=1:1:length(rad)
        [y0detect,x0detect,Accumulator] = houghcircle(Iedge,rad(1,radIndex),rad(1,radIndex)*pi/2);
    
        if ~isempty(y0detect)
            circles = struct;
            circles.X = x0detect;
            circles.Y = y0detect;
            circles.Rad = rad(1,radIndex);
            detectedCircle{detectedCircleIndex} = circles;
            detectedCircleIndex = detectedCircleIndex + 1;
        end
    end
    
    % For each detection run a color filter
    ang=0:0.01:2*pi; 
    finalCircles = {};
    finalCircleIndex = 1;
    
    for i=1:1:detectedCircleIndex-1
    
        rad = detectedCircle{i}.Rad;
        xp = rad*cos(ang);
        yp = rad*sin(ang);
    
        for detectedPointIndex=1:1:length(detectedCircle{i}.X)
    
            % Take each detected center and sample the gray image
            samplePointsX = round(detectedCircle{i}.X(detectedPointIndex) + xp);
            samplePointsY = round(detectedCircle{i}.Y(detectedPointIndex) + yp);
    
            sampleValueInd = sub2ind([row,col],samplePointsY,samplePointsX);
            sampleValueMean = mean(Igray(sampleValueInd));
    
            % Check if the circle color is good
            if(sampleValueMean > minValueWindow && sampleValueMean < maxValueWindow)
                circle = struct();
                circle.X = detectedCircle{i}.X(detectedPointIndex);
                circle.Y = detectedCircle{i}.Y(detectedPointIndex);
                circle.Rad = rad;
                finalCircles{finalCircleIndex} = circle;
                finalCircleIndex = finalCircleIndex + 1;
            end
        end
    end
    
    % Find Main circle by merging close hyptosis together
    for finaCircleInd=1:1:length(finalCircles)
        circleCenter(finaCircleInd,1) = finalCircles{finaCircleInd}.X;
        circleCenter(finaCircleInd,2) = finalCircles{finaCircleInd}.Y;
        circleCenter(finaCircleInd,3) = finalCircles{finaCircleInd}.Rad;
    end
    [ind,C] = kmeans(circleCenter,2);
    c = [length(find(ind==1));length(find(ind==2))];
    [~,maxInd] = max(c);
    xCircle = median(circleCenter(ind==maxInd,1));
    yCircle = median(circleCenter(ind==maxInd,2));
    radCircle = median(circleCenter(ind==maxInd,3));
    % Plot circle
    imshow(Igray);
    hold on
    
    ang=0:0.01:2*pi;
    xp=radCircle*cos(ang);
    yp=radCircle*sin(ang);
    plot(xCircle+xp,yCircle+yp,'Color','red', 'LineWidth',5);
    
    全部清除
    %参数
    最小值窗口=90;
    maxValueWindow=110;
    %读取文件
    I=imread('image1.jpg');
    Igray=rgb2gray(I);
    [行,列]=大小(Igray);
    %边缘检测
    Iedge=边缘(Igray,'canny',[0.3]);
    %霍夫圆变换
    rad=40:80;%以像素为单位的近似半径
    detectedCircle={};
    检测到的CircleIndex=1;
    对于半径,X=1:1:长度(rad)
    [y0detect,x0detect,累加器]=霍夫圆(Iedge,rad(1,radIndex),rad(1,radIndex)*pi/2);
    if~为空(y0detect)
    圆圈=结构;
    圆X=x0detect;
    圆。Y=y0detect;
    圆。Rad=Rad(1,radIndex);
    detectedCircle{detectedCircleIndex}=圆;
    detectedCircleIndex=detectedCircleIndex+1;
    终止
    终止
    %对于每个检测,运行一个颜色过滤器
    ang=0:0.01:2*pi;
    finalCircles={};
    最终循环指数=1;
    对于i=1:1:detectedCircleIndex-1
    rad=检测到的圆{i}.rad;
    xp=rad*cos(ang);
    yp=rad*sin(ang);
    对于detectedPointIndex=1:1:长度(detectedCircle{i}.X)
    %取每个检测到的中心并对灰度图像进行采样
    samplePointsX=圆形(detectedCircle{i}.X(detectedPointIndex)+xp);
    samplePointsY=round(detectedCircle{i}.Y(detectedPointIndex)+yp);
    sampleValueInd=sub2ind([row,col],samplePointsY,samplePointsX);
    sampleValueMean=平均值(Igray(sampleValueInd));
    %检查圆圈颜色是否良好
    if(sampleValueMean>minValueWindow&&sampleValueMean
    生成的图像:

    备注:

    • 对于其他图像,仍需微调多个参数,如搜索颜色的半径、Hough圆阈值和canny边缘阈值
    • 在函数中,我搜索半径从40像素到80像素的圆。在这里,您可以使用有关窗口真实世界半径和相机分辨率的先验信息。如果您知道相机与飞机的大致距离、相机的分辨率以及以厘米为单位的窗口半径,则可以使用该值获取以像素为单位的半径,并将其用于hough圆变换

    听起来很先进。首先,你需要知道飞机的所有参数——高度、角的圆度等等。然后从哪个角度拍摄照片/视频。根据这些参数,您可以在图像/视频中检测平面的前、上、下坐标,并创建(例如)矩形,用作测量/地图。完成后,您可以在飞机内搜索对象并测量它们。您需要在浏览器中找到的功能中使用(您需要将它们与您的图像匹配)。它有很多功能。我没有在这个主题,但我知道,你可以找到许多简单的功能,这样做,你需要匹配到你的图像(没有人会为你这样做:)。首先,你需要校准的径向失真的相机在所有你的图像。否则,尺寸将被扭曲,并且在不同的图像中确实不同。好的,谢谢。这里的挑战可能是您提到的另一个圆圈(如公司徽标或任何其他绘画)。那么,什么样的过滤和技术可以用来准确地找到我需要的窗口呢。有用于过滤的示例代码吗?您可以使用窗口和圆圈的颜色。也许还能识别出另一个显著的特征,比如门