当前位置:   article > 正文

【计算机视觉】【车辆识别】--Matlab实现_g=rgb2gray(i);g=g+100;

g=rgb2gray(i);g=g+100;

希望利用计算机自动计算出停车场车辆数目:

这里由于没有参考背景图,只有这一张,所以我采用的是对图像二值化,腐蚀膨胀,并且对白车、棕车、黑车各有一个阈值,之后计算图像域数量,则分别可以得到白车、黑车、棕车的数量,加在一起则是总数量,这里得到的结果是11.5辆。

  1. clc;
  2. clear all
  3. I=imread('D:/作业1.png');
  4. G=rgb2gray(I);
  5. % G=histeq(G);
  6. H=imhist(G);
  7. % bar(H);
  8. [a,b]=size(G);
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取白车
  10. G=G-100;
  11. for i=1:1:a
  12. for j=1:1:b
  13. if G(i,j)>=25
  14. G2(i,j)=1;
  15. else
  16. G2(i,j)=0;
  17. end
  18. end
  19. end
  20. se1=strel('square',10);
  21. G4=imdilate(G2,se1);
  22. se1=strel('square',15);
  23. G4=imerode(G4,se1);
  24. XX=bwlabel(G4,8);
  25. white=max(max(XX))/2%%%%%%%%%%%%%两个点为1个白车
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取黑车
  27. G=rgb2gray(I);
  28. G=G+100;
  29. [a,b]=size(G);
  30. for i=1:1:a
  31. for j=1:1:b
  32. if G(i,j)<=150
  33. G1(i,j)=1;
  34. else
  35. G1(i,j)=0;
  36. end
  37. end
  38. end
  39. se1=strel('square',20);%20
  40. G4=imerode(G1,se1);
  41. se1=strel('square',35); %35
  42. G5=imdilate(G4,se1);
  43. XX1=bwlabel(G5,8);
  44. black=max(max(XX1))-2%%%%%%%%%%%%%%减去两个背景
  45. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取棕车
  46. G=rgb2gray(I);
  47. [a,b]=size(G);
  48. for i=1:1:a
  49. for j=1:1:b
  50. if G(i,j)<=100&&G(i,j)>=70
  51. G1(i,j)=1;
  52. else
  53. G1(i,j)=0;
  54. end
  55. end
  56. end
  57. se1=strel('square',30);
  58. G4=imerode(G1,se1);
  59. se1=strel('square',30);
  60. G5=imdilate(G4,se1);
  61. XX2=bwlabel(G5,8);
  62. brown=max(max(XX2))-1%%%%%%%%%%%%减去中间背景点
  63. XX3=XX1+XX2+XX;
  64. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%出图
  65. subplot 221
  66. imshow(I)
  67. subplot 222
  68. % X1=double(G)-XX*255;
  69. % imshow(X1/255)
  70. imshow(XX)
  71. subplot 223
  72. imshow(XX1)
  73. % X2=double(G)-XX1*255;
  74. % imshow(X2/255)
  75. % imshow(XX1)
  76. subplot 224
  77. % X3=double(G)-XX2*255;
  78. % imshow(X3/255)
  79. imshow(XX2)
  80. sum=white+black+brown

11.5

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/129557
推荐阅读
相关标签
  

闽ICP备14008679号