%---------- int camera ---------------------
hwInfo = imaqhwinfo('winvideo');
device1 = hwInfo.DeviceInfo(1);
device1.SupportedFormats;
vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'ReturnedColorSpace','rgb');
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1);
set(vid,'TriggerRepeat', 100000);
start(vid);
%------- pp db 25 int commands ------------
dio1=digitalio('parallel','lpt1');
outreg=addline(dio1,0:7,0,'out');
%-------- taking values -------------
trigger(vid);
image1=getdata(vid,1);
imshow(image1);
%-------- main loop -----------------
for i=1:1500
trigger(vid);
image1=getdata(vid,1);
image1_r=image1(:,:,1);
image1_g=image1(:,:,2);
image1_b=image1(:,:,3);
image1_r1=im2bw(image1_r,140/255);
image1_g1=im2bw(image1_g,130/255);
image1_b1=im2bw(image1_b,130/255);
img=(image1_r1-image1_g1)-image1_b1;
img=img*255;
img=uint8(img);
img=bwareaopen(img,30);
img1=imfill(img,'holes');
[x1 y1]=bwlabel(img1);
if (y1 >0)
[x y]=find(img1==1);
mean_x=fix(mean(x));
mean_y=fix(mean(y));
if (mean_x > 60 && mean_x < 180 && mean_y > 80 && mean_y < 240)
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),0);
else if (mean_x > 0 && mean_x < 60 && mean_y > 80 && mean_y < 240)
putvalue(dio1.line(1),1);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),0);
else if (mean_x > 180 && mean_x < 240 && mean_y > 80 && mean_y < 240)
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),1);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),0);
else if (mean_x > 0 && mean_x < 240 && mean_y > 0 && mean_y < 80)
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),1);
putvalue(dio1.line(4),0);
else if (mean_x > 0 && mean_x < 240 && mean_y > 240 && mean_y < 320)
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),1);
else
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),0);
end
end
end
end
end
string=strcat(num2str(mean_x),'and',num2str(mean_y));
image2(:,:,1)=double(image1(:,:,1)) .* double(img1);
image2(:,:,2)=double(image1(:,:,2)) .* double(img1);
image2(:,:,3)=double(image1(:,:,3)) .* double(img1);
image2=uint8(image2);
subplot(1,2,1)
imshow(image1)
title('orignal image')
subplot(1,2,2)
imshow(image2);
title(string);
else
subplot(1,2,1)
imshow(image1)
title('no object detected')
subplot(1,2,2)
imshow(image1)
title('no object detected')
putvalue(dio1.line(1),0);
putvalue(dio1.line(2),0);
putvalue(dio1.line(3),0);
putvalue(dio1.line(4),0);
end
end