matlab code overload (busy) and not doing what it's supposed to do
Show older comments
Hi
I have written an image acquisision and proccessing code which is invoked every time a timer object stops running, or not responding.
the whole project consists 3 fuctions: 1)timer definition 2)image acquisition 3)image processing
when Im debugging the program, everything is working great. when Im making an executable of my program usin the deployment tool, it starts, but closes itself, or not doing anything. if it doesnt close, it just overloads my cpu (to 100%).
The algorithm's run time is infinite, because I am running the timer at a 'fixed spacing' running mode.
the codes are:
1)
function []= timer_me()
clear
clc
close all
%a=imread('tire.tif');
%imshow(a);
global oldfile;
path = 'C:\MATLAB PROJECTS\dirtest';
test=dir(path);
oldfile=test(size(test)).name;
out = timerfind('Name', 'ReadImageTimer');
if(size(out)==0)
t = timer('Name','ReadImageTimer',...
'ExecutionMode', 'fixedSpacing',...
'TimerFcn',@readimage,...
'Period',0.5 );
start(t);
end
while(1);
end-----------------------------
2)
function [ ] = readimage(arg1, arg2, arg3)
path = 'C:\MATLAB PROJECTS\dirtest';
test=dir(path);
filename=test(size(test)).name;
global oldfile
if(~strcmp(oldfile, filename))%IS THE OLDEST FILE IN THE
%DIRECTORY NEW?
i=imread([path '\\' filename]);
imshow(i);
[hit]=coloralg(i);
oldfile=filename;
hit
subplot(2,1,1), imshow(i);
if(hit == 1)
subplot(2,1,1), imshow(i);
xlabel('hit!')
ylabel('hit!')
else
xlabel('miss!')
ylabel('miss!')
end
else
a='same'
end
% start(timer)
end
-------------------------
3)
function [hit] = coloralg(x)
%type=3; %in the actual func will get 1/2/3 according to R/G/B
%[x]=imread('black_red.jpg');
%x=data;
subplot(2,1,1), imshow(x), ylabel('before');
xred=x(:,:,1);
%xgreen=x(:,:,2);
%xblue=x(:,:,3);
[numr,numc,null]=size(x);
quant=90;
for r=1:numr
for c=1:numc
if x(r,c,1)>110
if x(r,c,2)<230
if x(r,c,3)<230
x(r,c,:)=255;
else
x(r,c,:)=0;
end
else
x(r,c,:)=0;
end
else
x(r,c,:)=0;
end
end
end
%xafterred=x(:,:,1);
%xaftergreen=x(:,:,2);
%xafterblue=x(:,:,3);
subplot(2,1,2), imshow(x), ylabel('after ');
middlex=round(size(x)/2);
middlexr=[middlex(1),middlex(2)];
measurepointr = [middlexr(1), middlexr(2) , 1];
wtf=x(measurepointr(1),measurepointr(2),1)
a=imread('tire.tif');
imshow(a);
if(wtf == 255)
hit = 1;
else
hit = 0;
end
------------
Can somebody help me please?
Matar Maoz
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!