how to flip image in real time video using matlab

2
Jans Hendry / EE&IT UGM INDONESIA 2011 1 OBJECT FLIPPING IN REAL TIME VIDEO This idea comes up when i found that my webcam displays my picture flipped. It means when you wave your right hand, webcam display it in the left side, viceversa. Well, it will be a big issue when we want to use image acquired as mouse controller. My first idea is to give simple computation for matlab to understand which is right hand and which is not. But it ends up to what so called as non- proffesional code programming. Haha... Now i try to develop a code to flip each frame catched by matlab. This code use fliplr toolbox or maybe you can try fliprl, in my mind thay will contribute same result. Steps you may follow to flip object in real time video is as below: - Get one frame to process - In this case, we set ReturnedColorspace property to RGB. Then, we separate them into R, G and B component. After that we flip each component then mix them using ‘cat’ toolbox. Below program shows you how this is can be done. clear all; close all; clc; imaqreset; caminf = imaqhwinfo; mycam = char(caminf.InstalledAdaptors(end)); mycaminfo = imaqhwinfo(mycam); resolution = char(mycaminfo.DeviceInfo.SupportedFormats(end)); vid = videoinput(mycam, 1, resolution); set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb'); vid.FrameGrabInterval = 3; screenSize = get(0, 'screensize'); width=screenSize(3); height=screenSize(4); framesneed=300; % or you can write Inf. start(vid) while(vid.FramesAcquired<=framesneed) dataa = getsnapshot(vid); % flipping each frame data1=dataa(:,:,1); data1=fliplr(data1); data2=dataa(:,:,2); data2=fliplr(data2); data3=dataa(:,:,3); data3=fliplr(data3);

Upload: jans-hendry

Post on 05-Mar-2015

1.166 views

Category:

Documents


2 download

DESCRIPTION

Jans Hendry / EE&IT UGM INDONESIA2011OBJECT FLIPPING IN REAL TIME VIDEOThis idea comes up when i found that my webcam displays my picture flipped. It means when you wave your right hand, webcam display it in the left side, viceversa. Well, it will be a big issue when we want to use image acquired as mouse controller. My first idea is to give simple computation for matlab to understand which is right hand and which is not. But it ends up to what so called as nonproffesional code programming

TRANSCRIPT

Page 1: How to Flip Image in Real Time Video Using Matlab

Jans Hendry / EE&IT UGM INDONESIA

2011

1

OBJECT FLIPPING IN REAL TIME VIDEO

This idea comes up when i found that my webcam displays my picture flipped. It means when you

wave your right hand, webcam display it in the left side, viceversa. Well, it will be a big issue when

we want to use image acquired as mouse controller. My first idea is to give simple computation for

matlab to understand which is right hand and which is not. But it ends up to what so called as non-

proffesional code programming. Haha...

Now i try to develop a code to flip each frame catched by matlab. This code use fliplr toolbox or

maybe you can try fliprl, in my mind thay will contribute same result.

Steps you may follow to flip object in real time video is as below:

- Get one frame to process

- In this case, we set ReturnedColorspace property to RGB. Then, we separate them into

R, G and B component. After that we flip each component then mix them using ‘cat’ toolbox.

Below program shows you how this is can be done.

clear all; close all; clc; imaqreset;

caminf = imaqhwinfo; mycam = char(caminf.InstalledAdaptors(end)); mycaminfo = imaqhwinfo(mycam); resolution = char(mycaminfo.DeviceInfo.SupportedFormats(end));

vid = videoinput(mycam, 1, resolution); set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb'); vid.FrameGrabInterval = 3;

screenSize = get(0, 'screensize'); width=screenSize(3); height=screenSize(4); framesneed=300; % or you can write Inf.

start(vid)

while(vid.FramesAcquired<=framesneed)

dataa = getsnapshot(vid);

% flipping each frame data1=dataa(:,:,1); data1=fliplr(data1); data2=dataa(:,:,2); data2=fliplr(data2); data3=dataa(:,:,3); data3=fliplr(data3);

Page 2: How to Flip Image in Real Time Video Using Matlab

Jans Hendry / EE&IT UGM INDONESIA

2011

2

data=cat(3,data1,data2,data3);

flushdata(vid); % to clear memory

imshow(data); end

stop(vid); delete(vid); imaqreset;

First picture below will show you the original image catch by webcam through matlab and second

image is flipped image.

Flipped image

~~~ THANKS ~~~