how to extract rgb value from each frameof video for a real time application?

1 view (last 30 days)
my objective is to predict the organic matter content of soil from the RGB value of image for real time basis..for my project..a gps and scout camera will be mounted to a tractor..as the tractor move, i want the r,g,b value of each video frame, latitude and longitude will be logged for every second and display in a table..is this possible?
this is my coding..i'm using for loop,so the real time application cannot be achieved..how can i change the coding so the r,g,b, lat & long can be log n display every second???? any help will be useful..tq very much..
clear all, close all;
tic
for i=1:50;
if i==1
vidobj = videoinput ('winvideo',1,'YUY2_160x120');
start (vidobj)
preview (vidobj)
obj1= instrfind('Type', 'serial', 'Port', 'COM9', 'Tag', '');
k=1;
%create the serial port object if it does not exist
%otherwise use the object that was found.
if isempty (obj1)
obj1 = serial ('COM9');
else
fclose (obj1);
obj1= obj1 (1);
end
%set Baudrate at 4800.
obj.Baudrate = 4800;
%connect to instrument object, obj1.
fopen(obj1);
data='';
while isempty (strmatch ('$GPPGA', data))
data = fscanf (obj1);
end
%Parse the string to obtain coordinates
[lat,data] = strtok(data,',');
[nsCardinal,data] = strtok (data,',');
[long,data] = strtok(data,',');
[ewCardinal,data] = strtok (data,',');
lat = str2doule (lat);
long = str2doule (long);
%Display results
disp ({lat,nscardinal,long,ewcardinal});
snapshot = getsnapshot (vidobj);
imagesc (snapshot);
set (vidobj, 'ReturnedcolorSpace','rgb');
image =(snapshot);
red= image (:,:,1);
green= image (:,:,2);
blue= image (:,:,3);
meanRed = mat2str (mean2(red));
meanGreen = mat2str (mean2(green));
meanBlue = mat2str (mean2(blue));
a= 80.917;
r= 0.246;
g= 0.272;
b= 0.278;
allMean = { meanRed meanGreen meanBlue lat long};
AllData (:,k)= {allMean};
K=k+1;
end
toc
for i=1:n
Arrange (i,:)= AllData {1,i};
MeanR (i,1)=str2double (Arrange {i,1});
MeanG (i,1)=str2double (Arrange {i,2});
MeanB (i,1)=str2double (Arrange {i,3});
lat (i,1)= str2double (Arrange {i,4});
long (i,1)= str2double (Arrange {i,5});
organicMatter (i,1)= a+r* MeanR (i,:) - g* MeanG (i,:) - b*MeanB (i,:);
end
All_FinalData= [MeanR MeanG MeanB lat long organicmatter];
end

Answers (0)

Categories

Find more on Programming Utilities 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!