当前位置:   article > 正文

【农田杂草识别】基于sift特征提取的农田杂草识别_牧草识别 fpga

牧草识别 fpga
  1. clc;
  2. clear;
  3. close all;
  4. warning off;
  5. addpath 'func\'
  6. %1的话设置连线
  7. Feature_point = 1;
  8. %是否需要重新特征提取,%1:对以一组新的图片,需要选择1,对于同一组图片,直接设置0
  9. sel = 1;
  10. t = sqrt(2).^([0]);%选择不同的角度t,arccos(1/t);
  11. %读取图片
  12. img1 = imresize(imread('A1.jpg'),0.8);
  13. img2 = imresize(imread('杂草模板\B.jpg'),0.8);
  14. %转换为灰度图
  15. [R,C,K] = size(img1);
  16. if K == 3
  17. img1s = rgb2gray(img1);
  18. else
  19. img1s = img1;
  20. end
  21. [R,C,K] = size(img2);
  22. if K == 3
  23. img2s = rgb2gray(img2);
  24. else
  25. img2s = img2;
  26. end
  27. %计算图片的大小
  28. [m1,n1] = size(img1s);
  29. [m2,n2] = size(img2s);
  30. %对两个图片分别进行角度选择和不同角度的特征提取
  31. if sel == 1
  32. tic;
  33. disp('对图片1进行处理');
  34. [Hrl_feature1,Hr_pointl_feature1,cnt1]=func_sift_angle(img1s,m1,n1,t);
  35. Time = toc;
  36. disp('对图片2进行处理');
  37. [Hrl_feature2,Hr_pointl_feature2,cnt2]=func_sift_angle(img2s,m2,n2,t);
  38. save feature_data_B1.mat Hrl_feature1 Hr_pointl_feature1 Hrl_feature2 Hr_pointl_feature2 cnt1 cnt2 Time
  39. else
  40. load feature_data_B1.mat
  41. end
  42. %进行配准
  43. pp = 0;
  44. level = 0.7;%这个参数要根据不同的测试样本进行调整
  45. image_match1 = [];
  46. image_match2 = [];
  47. for i = 1:(cnt1 - 1)
  48. for j = 1:(cnt2 -1)
  49. pp = pp + 1;
  50. fprintf('处理进度:');fprintf('%3.2f',100*pp/(cnt1*cnt2));fprintf('%%\n\n');
  51. NF1(i) = size(Hrl_feature1{i},1);
  52. NF2(j) = size(Hrl_feature2{j},1);
  53. same_feature = func_feature_match(Hrl_feature1{i},Hrl_feature2{j},level);
  54. ind1 = find(same_feature);
  55. ind2 = same_feature(ind1);
  56. %根据门限来选择一定区域内的配准点
  57. ind = find(sqrt(sum(((Hrl_feature1{i}(ind1,:)-Hrl_feature2{j}(ind2,:)).^2),2)) <= level);
  58. ind1 = ind1(ind);
  59. ind2 = ind2(ind);
  60. Match1Tmp = Hr_pointl_feature1{i}(ind1,[ 1 2 3 end ]);
  61. Match2Tmp = Hr_pointl_feature2{j}(ind2,[ 1 2 3 end ]);
  62. image_match1 = [image_match1;Match1Tmp];
  63. image_match2 = [image_match2;Match2Tmp];
  64. end
  65. end
  66. close all;
  67. %显示最后处理的定位效果
  68. [LineCoordX,LineCoordY,N] = func_figure(img1s,image_match1,img2s,image_match2,Feature_point);
  69. figure;
  70. imshow(img1);
  71. hold on
  72. r=40;
  73. theta=0:pi/50:2*pi;
  74. for i = 1:N
  75. x0=LineCoordX(1,i);
  76. y0=LineCoordY(1,i);
  77. x=x0+r*cos(theta);
  78. y=y0+r*sin(theta);
  79. plot(x,y,'g-','linewidth',2);
  80. hold on
  81. end

 

A10-49

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

闽ICP备14008679号