使用MATLAB在图像中识别LED屏幕

时间:2014-01-03 18:03:11

标签: matlab image-processing image-recognition

我正在尝试从图像中检测屏幕边框(需要4个角)。 这是图片:

enter image description here

我使用HOUGH变换来检测线条和交叉点(黑色圆圈),这就是结果:

enter image description here

现在我需要找到4个角或4个线......所有可以帮助我裁剪图像的东西,我该怎么办? 也许使用屏幕宽高比?但怎么样? 我正在使用Matlab。

感谢。

1 个答案:

答案 0 :(得分:0)

当且仅当您具有相同的图像条件(背景和笔记本电脑)时,一种天真的第一种方法可以做到这一点。

  1. 将您的图像转换为HSV(在HSV中检查图像中的图像 屏幕是图像中唯一具有高饱和度,值的部分 值)
  2. 通过对阈值和值通道进行硬阈值处理来创建遮罩
  3. 扩大遮罩以连接断开连接的区域
  4. 计算凸包以获得蒙版边界
  5. 查看快速结果: enter image description here 这是与原始图像部分相同的蒙版,使其通过蒙版: enter image description here

    以下是执行此操作的代码:

    img = imread( 'imagename.jpg'); % change the image name
    hsv = rgb2hsv( img);
    mask = hsv(:,:,2)>0.25 & hsv(:,:,3)>0.5;
    strel_size = round(0.025*max(size(mask)));
    dilated_mask=imdilate(mask,strel('square',strel_size));
    s=regionprops(dilated_mask,'BoundingBox','ConvexHull');
    % here Bounding box produces a box with the minimum-maximum white pixel positions but the image is not actually rectangular due to perspective...
    imshow(uint8(img.*repmat(dilated_mask,[1 1 3])));
    line(s.ConvexHull(:,1),s.ConvexHull(:,2),'Color','red','LineWidth',3);
    


    当然,您可以应用一些更复杂的处理来更准确,并将凸包校正为具有透视的矩形形状,但这仅仅是为了展示该方法的5分钟尝试...