EGG CRACK DETECTION :(

Im having hard time coding this but looks like i need help :)
Clc;
Clear all;
Close all;
Input_Image=captureImg();
%[filename,pathname] = uigetfile(‘*.*’);
%eggImage1=imread([pathname filename]);
%eggImage1=imread(‘C’);
%figure;imshow(eggImage1); title(‘Original image’);
%%detect and extract regions
grayImage=rgbygray(Input_Image);
edgeimage = edge(grayImage,canny,0.31691);
%
%
%
Old
bwImage = im2bw(grayImage,0.9999);
figure;imshow(bwImage);title(BW image)
BW1 = edge(R,'sobel',0.9);
BW2 = edge(R,'canny',0.3);
figure;
imshowpair(BW1,BW2,'montage')
title('Sobel Filter Canny Filter');
BW1 = edge(grayImage,'sobel',0.9);
BW2 = edge(grayImage,'canny',0.3);
!
51!
figure;
imshowpair(BW1,BW2,'montage')
title('Sobel Filter Canny Filter');
bwR = im2bw(R,0.18);
figure, imshow(bwR); title('BW of Range Filtered image')
%J = entropyfilt(grayImage);
S = stdfilt(grayImage);
figure, imshow(S,[]); title('Std Filtered image')
bwR = im2bw(R);
figure, imshow(bwR); title('BW of Range Filtered image')
%}
saveName = strcat('D:\Wood Dimension\CaptImgs\','',num2str(no),'.jpg'); baseDir = 'D:\Wood Dimension\CaptImgs\'; newName = [baseDir num2str(no) '.jpg']; imwrite(Input_Image,newName); %%Find File information %info = imfinfo([path_name file_name]); info = imfinfo(newName);
thres = graythresh(Input_Image);
GS_Image = rgb2gray(Input_Image);
filt_im = medfilt2(GS_Image, [3 3]);
imtool(filt_im);
thres = graythresh(filt_im);
BW_Image = ~(im2bw(filt_im,thres));%tilde for light BG, dark FG
%figure,imshow(BW_Image);
BW_Image = bwareaopen(BW_Image,100);
Comp_Image = bwconncomp(BW_Image);%Connected Component of BW image
!
52!
stats = regionprops(Comp_Image, {'BoundingBox'});
W_pix = stats.BoundingBox(3);
H_pix = stats.BoundingBox(4);
%pause(10);
%W_pix
%H_pix
disp('DIMENSTIONS OF METAL IN Cm');
H=H_pix/69.77;
W=W_pix/75.06;
H=['Height is ',num2str(H),' cm']
W=['Width is ',num2str(W),' cm']
bwAreaopen = bwareaopen(edgeImage,200);
BW = bwAreaopen;
crack_pix = 0;
[B,L,N] = bwboundaries(BW);
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2),...
boundary(:,1),'g','LineWidth',2);
crack_pix = crack_pix + 1;
end
end
crack_pix = W_pix;
if crack_pix >= 610
%seial_send('c'); %Cracked
disp('Cracked');
else
%serial_send('n'); %Not Cracked
!
53!
disp('Metal is Normal');
end
close all;
%%%%%%%%%%%%%%Serial send%%%%%%%%%%%%%%%%%%
function serial_send(Msg)
global COM;
COM = serial('COM3','BaudRate',9600,'DataBits',8);
fopen(COM);
disp('Sending...');
pause(2);
fprintf(COM,'%s',Msg);
disp(Msg);
pause(3);
fclose(COM);
delete(COM);
clear COM;
disp('Closing COM port');
end
%%%%%%%%%%%%%%%%%%%Capture %%%%%%%%%%%%%%%%%%%%
function serial_send(Msg)
global COM;
COM = serial('COM3','BaudRate',9600,'DataBits',8);
fopen(COM);
!
54!
disp('Sending...');
pause(2);
fprintf(COM,'%s',Msg);
disp(Msg);
pause(3);
fclose(COM);
delete(COM);
clear COM;
disp('Closing COM port');
end
%%%%%%%%%%%%%%%%%%%%%serial rcv
%%%%%%%%%%%%%%%%%%%%%
function [rcv_cmd] = serial_rcv()
global ser;
ser = serial('COM4','BaudRate',9600,'DataBits',8);
fopen(ser);
rcv_cmd = fscanf(ser,'%s');
fclose(ser);
delete(ser);
clear ser;
end

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Import, Export, and Conversion 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by