当前位置:网站首页>[chapter 04 answer sheet recognition based on Hough change]

[chapter 04 answer sheet recognition based on Hough change]

2022-06-22 01:54:00 Haibao 7

The whole system MATLAB Deep learning of intelligent driving hough Transformation to realize case application

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
Function comparison basis , It is not difficult to apply , Mainly tend to image recognition and simple processing .
The main function is as follows
main.m

clc; clear all; close all;
warning off all;
I = imread('images\\1.jpg');
I1 = Image_Normalize(I, 1);
hsize = [3 3];
sigma = 0.5;
I2 = Image_Smooth(I1, hsize, sigma, 1);
I3 = Gray_Convert(I2, 1);
bw2 = Image_Binary(I3, 1);
figure; subplot(1, 2, 1); imshow(I, []); title(' Original image ');
subplot(1, 2, 2); imshow(bw2, []); title(' Binary image ');
[~, ~, xy_long] = Hough_Process(bw2, I1, 1);
angle = Compute_Angle(xy_long);
[I4, bw3] = Image_Rotate(I1, bw2, angle*1.8, 1);
[bw4, Loc1] = Morph_Process(bw3, 1);
[Len, XYn, xy_long] = Hough_Process(bw4, I4, 1);
[bw5, bw6] = Region_Segmation(XYn, bw4, I4, 1);
[stats1, stats2, Line] = Location_Label(bw5, bw6, I4, XYn, Loc1, 1);
[Dom, Aom, Answer, Bn] = Analysis(stats1, stats2, Line, I4);

Hough Function transformation
namely Hough_Process.m

function [Len, XYn, xy_long] = Hough_Process(bw, Img, flag)

if nargin < 3
    flag = 1;
end
[H, T, R] = hough(bw);
P = houghpeaks(H, 4, 'threshold', ceil(0.3*max(H(:))));
lines = houghlines(bw, T, R, P, 'FillGap', 50, 'MinLength', 7);
max_len = 0;
for k = 1 : length(lines)
    xy = [lines(k).point1; lines(k).point2]; 
    len = norm(lines(k).point1-lines(k).point2); 
    Len(k) = len;
    if len > max_len
        max_len = len;
        xy_long = xy;
    end
    XY{k} = xy; %  Store information 
end
[Len, ind] = sort(Len(:), 'descend'); %  Sort by length 
%  Line information sorting 
for i = 1 : length(ind)
    XYn{i} = XY{ind(i)};
end
xy_long = XYn{1};
x = xy_long(:, 1);
y = xy_long(:, 2);
if abs(diff(x)) < abs(diff(y))
    x = [mean(x); mean(x)];
else
    y = [0.7*y(1)+0.3*y(2); 0.3*y(1)+0.7*y(2)];
end
xy_long = [x y];
if flag
    figure('units', 'normalized', 'position', [0 0 1 1]);
    subplot(2, 2, 1); imshow(bw); title(' Binary image ', 'FontWeight', 'Bold');
    subplot(2, 2, 2); imshow(H, [], 'XData', T, 'YData', R, 'InitialMagnification', 'fit');
    xlabel('\theta'); ylabel('\rho');
    axis on; axis normal; title(' Hough transform domain ', 'FontWeight', 'Bold')
    subplot(2, 2, 3); imshow(Img); title(' Original image ', 'FontWeight', 'Bold');
    subplot(2, 2, 4); imshow(Img); title(' Area identification image ', 'FontWeight', 'Bold');
    hold on;
    plot(xy_long(:,1), xy_long(:,2), 'LineWidth', 2, 'Color', 'r');
end

Region partition subfunction
Region_Segmation.m

function [bw1, bw2] = Region_Segmation(XY, bw, Img, flag)

if nargin < 4
    flag = 1; 
end

for i = 1 : 2
    xy = XY{i}; 
    XY{i} = [1 xy(1, 2); size(bw, 2) xy(2, 2)];
    ri(i) = round(mean([xy(1,2) xy(2,2)]));
end
minr = min(ri);
maxr = max(ri);
bw1 = bw; bw2 = bw;
bw1(1:minr+5, :) = 0;
bw1(maxr-5:end, :) = 0;
bw2(minr-5:end, :) = 0;
bw2(1:round(minr*0.5), :) = 0;

if flag
    figure('units', 'normalized', 'position', [0 0 1 1]);
    subplot(2, 2, 1); imshow(Img, []); title(' Original image ', 'FontWeight', 'Bold');
    subplot(2, 2, 2); imshow(bw, []); title(' Original binary image ', 'FontWeight', 'Bold');
    hold on;
    for i = 1 : 2
        xy = XY{i}; 
        plot(xy(:, 1), xy(:, 2), 'r-', 'LineWidth', 2);
    end
    hold off;
    subplot(2, 2, 3); imshow(bw1, []); title(' Lower area image ', 'FontWeight', 'Bold');
    subplot(2, 2, 4); imshow(bw2, []); title(' Upper area image ', 'FontWeight', 'Bold');
end

Other specific function list files
 Insert picture description here
Full set of file source code –> Portal

原网站

版权声明
本文为[Haibao 7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220101378803.html