You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
video stream height measurement
8 views (last 30 days)
Show older comments
i m working on video analysing program where i have to measure the height of the incoming video stream object, Now i took the video stream into the matlab. I couldnt do the measurement part .Can u pls help me with this analysing part.
4 Comments
Walter Roberson
on 23 Jan 2013
Are the objects always the same distance away? Is the camera always using the same aperture? Or does each image contain an object of known size?
Jack Sparrow
on 23 Jan 2013
I think you need to know atleast the intrinsic or extrinsic parameter of the camera or atleast have an object in the reference area. I'm currently working on something close to this for my M.Sc but i'm stalk at calculating the vanishing point in the image after getting the vanishing lines.
M DINESH
on 23 Jan 2013
since my camera parameters are remain constant and also the reference object is located in the same distance. e.g.: I am lighting an candle from a fixed distance from a camera and i want to measure the height of the flame as a real time data. I m capturing the video and i m converting it to a image file and i m struck in measuring the flame height and plotted in an scaled graph like histogram
Accepted Answer
More Answers (2)
Walter Roberson
on 23 Jan 2013
Provided that the same aperture will always be used, since the object will always be at the same distance, the easiest way to proceed would be to start by inserting an object of known size into the scene, taking an image of it, and finding the height in pixels of the known real-world height. Once you have the height in pixels, you can trivially calculate a scaling factor between pixels and real-world.
After that, it just becomes a matter of figuring out the size in pixels of each presented object, and multiplying that by the real-world scale factor previously calculated. As long as nothing changes (e.g., distance does not change.)
16 Comments
Walter Roberson
on 23 Jan 2013
I do not think I understand what you mean about "the frame data only" ? How are you reading the frames?
M DINESH
on 23 Jan 2013
first i m getting the video and i am converting it to a image in 'png' format. i m using imread and getdata from image acquisition toolbox. Am i doning it correct way or it is some other syntax to find the height of the image.
Walter Roberson
on 23 Jan 2013
getdata() is suitable for getting an image from video. You could process that image directly, or you could write it out for later processing. If you did do later processing then you could imread() the saved image.
When you have an image in memory, you can do image processing on it to find the height in pixels, and then multiply the height in pixels by the pre-calculated scaling factor in order to find the real-world height.
Walter Roberson
on 24 Jan 2013
You are trying what ?
M DINESH
on 24 Jan 2013
Edited: Walter Roberson
on 24 Jan 2013
imread()
h=im2double()
height=size(h,1)
this is the syntax i have tried.
Walter Roberson
on 24 Jan 2013
As I wrote above,
After that, it just becomes a matter of figuring out the size in pixels of each presented object, and multiplying that by the real-world scale factor previously calculated.
You have not found the size in pixels of each presented object (in the image). You need to analyze the image content for that. The link I gave above should show some ideas on how to do that. The link was http://www.mathworks.co.uk/matlabcentral/answers/57813-image-color-segmentation-to-find-different-objects-of-a-candle
M DINESH
on 24 Jan 2013
Edited: Walter Roberson
on 24 Jan 2013
vid=videoinput('winvideo',1);
start(vid);
data=getdata(vid,1);
image(data);
im=find(data);
[x,y]=find(data);
x2=max(x);
x1=min(x);
y2=max(y);
y1=min(y);
y3=y2-y1;
i have used the above syntax for finding pixel values. but every time its showing the constant value.
help me with this to sort it out.
Walter Roberson
on 24 Jan 2013
Due to noise in video system hardware, it is not uncommon for "black" pixels to not be exactly 0, and chances are good that at least one pixel in any one row or column would be non-zero just because of noise. And if the background is not completely black, many more pixels would be non-0. You likely need to threshold the data at the very least.
Please save one of the frames as an image file and upload it so we can have a look at it; http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
M DINESH
on 25 Jan 2013
I used improfile to find out the RGB value and i put a RGB threshold value for red,green and blue region for the image and after that i read the pixel height and it is giving me the height of the pixel. I have tried for 10 nos of picture and the pixel height varies accordingly. But i have a doubt,whether the values are right or wrong. In next step, i need to bring the image and also the pixel value in GUI window . Need your help....
Walter Roberson
on 25 Jan 2013
Walter Roberson
on 25 Jan 2013
That seems to be an empty image.
M DINESH
on 25 Jan 2013
Edited: Walter Roberson
on 25 Jan 2013
im=imread('*.jpg');
red=im(:,:,1);
green=im(:,:,2);
blue=im(:,:,3);
light=red>200&green>200&blue>200;
[x,c]=find(light);
x2=max(x);
x1=min(x);
y2=max(c);
y1=min(c);
x2
774
x1
9
y2
765
y1
10
Warning: Image is too big to fit on screen; displaying at 56% scale.
this is the answer i got for pixel measurement.
13 Comments
Walter Roberson
on 25 Jan 2013
I don't think you can imread('*.jpg')
To work on a continuous stream, replace the imread() with the command to fetch a frame.
M DINESH
on 25 Jan 2013
Edited: Walter Roberson
on 25 Jan 2013
vid=videoinput('winvideo',1);
start(vid);
d=getdata(vid,1);
R=d(:,:,1);
G=d(:,:,2);
B=d(:,:,3);
light=R>200&G>200&B>200;
[x,y]=find(d);
x2=max(x);
x1=min(x);
y2=max(y);
y1=min(y);
x1
x2
y1
y2
This is the exact syntax's i have been tried for measuring pixel.
If this is right, help me to get the continuous video stream into the M-file for processing.
Walter Roberson
on 25 Jan 2013
Yes, use a while loop.
I do not know if the pixel measurement is right, as the image you posted earlier appears to be empty.
M DINESH
on 28 Jan 2013
Edited: Walter Roberson
on 28 Jan 2013
while executing the below code i m getting an error in 'while' loop.
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1);
set(vid,'TriggerRepeat', Inf);
start(vid);
while(1)
{
trigger(vid);
im= getdata(vid,1);
imshow(im);
}
end
stop(vid),delete(vid),clear vid;
This is the error i m getting .
??? Error: File: C:\MATLAB7\work\Untitled1.m Line: 9 Column: 4
The expression to the left of the equals sign is not a valid target for an assignment.
what i have to do for this.?????
Walter Roberson
on 28 Jan 2013
"while" loops do not use {} brackets in MATLAB.
M DINESH
on 28 Jan 2013
Edited: Walter Roberson
on 28 Jan 2013
while(1);
trigger(handles.video);
d=getdata(handles.video,1);
R=d(:,:,1);
G=d(:,:,2);
B=d(:,:,3);
light=R<20&G<20&B<20;
[x,y]=find(light);
x2=max(y);
handles.static Text.Value=x2;
end
Here i am trying to get the value of 'X2' in Static Text box and the value is not written.
Solution pls....
Walter Roberson
on 28 Jan 2013
set(handles.staticText, 'String', num2str(x2));
I have not bothered to analyze the image you posted to figure out whether the pixel measurements are right. I suggest that you display the image and draw vertical bars at min(y) and max(y) to see whether the results look reasonable.
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)