This program helps you to take photos using your web cam.
The photos taken will also saved as JPEG file. The name of this file will be assigned automatically.
The function 'videoinput' is used to create the object (obj). The argument winvideo is the adaptor name. If your adaptor is not this you can find the adaptor name by executing the command 'imaqhwinfo' on the command window. This will show all installed adaptors in the system. The 'preview' will immediately activates a live image preview window
for the video input object obj. This can be deactivated by using the function 'closepreview'. The 'getsnapshot' isused to take the photograph and it returns the image data array. 'imwrite' is used to save the image file.
Download:
MATLAB Program follows:
%-------------------------------------------------------------------------------------
% Program for taking photographs
% By vipin.p.nair
% 4-Nov-2008
% This program uses the web cam foR taking photos
%*********************************************************
% Algorithom
% 1) Read no of photos
% 2) Read intervel
% 3) initialise video device
% 4) show preview
% 5) loop: x[i]snapshot, if time increment i
% 6) show snaps in differnt figures goto loop
% 7) END
%**********************************************************
clc ; % clearing the command window
num = input(' Enter the number of photos to be taken: ');
intervel = input(' Enter the time(seconds) gap between succeessive photos: ');
photosave = input(' Do you want to save the files(y/n): ','s');;
disp('Please wait...');
obj = videoinput('winvideo',1);
preview(obj);
disp('You can adjust the video settings using your normal video console and after it press any key to start.');
pause;
disp('First shot will taken after 1 second');
pause(1);
for i=1:num
figure;
img=getsnapshot(obj);
image(img);
if(photosave == 'y')
filephoto= ['photo',int2str(i),'.jpg'];
imwrite(img,filephoto,'jpg');
end
pause(intervel);
end
closepreview;
disp('The program successfully taken the photos');
Wednesday, November 12, 2008
File Copier
"File copier" is a program to copy a file from one location to another using C.
Suppose you are copying a ".DAT" (video ) file from a scratched CD. If there is any error while reading , the data that is copied will also lose. But if you copy it with this the copied data will be remain in the destination. The number of errors present in the file will also displayed. This software will automatically correct many of the errors.
Download
The program code in turboc C as follows:
/* program to copy a file to another location
vipin.p.nair
s4 EC College of Engineering Kalooppara
20-march-2008
*/
#include
#include "stdio.h"
#include
void main()
{
char name[100],folder[100],ch,temp=0;
long counterror=0,size=0;
FILE *f,*d;
textcolor(BLUE);
textbackground(WHITE);
clrscr();
textcolor(WHITE);
textbackground(LIGHTBLUE);
gotoxy(20,4);
cprintf(" File Copier ");
gotoxy(10,6);
cprintf(" vipin.p.nair S4-EC-CEK-2008 ");
gotoxy(1,8);
cprintf("************************************************************");
printf("\n\n\n\tEnter the file to copy : ");
gets(name);
if((f=fopen(name,"rb"))==NULL)
{
fprintf(stderr, "\tCan't open input file.\n");
getch();
return;
}
printf("\tEnter the path of the destinaton file name :");
gets(folder);
if((d=fopen(folder,"wb"))==NULL)
{
fprintf(stderr, "\tCan't create output file.\n");
getch();
return;
}
fseek(f,0L,SEEK_END);
size=ftell(f);
printf("\n\tSize : %ld bytes\n",size);
fseek(f, 0L, SEEK_SET);
textbackground(WHITE );
textcolor(BLUE);
gotoxy(1,20);
cprintf("please wait...");
while(!feof(f))
{
ch=getc(f);
if(ferror(f))
{
putc(temp,d);
counterror++;
continue;
}
putc(ch,d);
temp=ch;
}
if(!counterror)
printf("\n\tThe file was successfully copied.");
else
printf("\n\tThe file was copied"
"\n\tthe number of errors encounterd was %lf",counterror);
fclose(f);
fclose(d);
getch();
}
HIDE A PHOTO INSIDE ANOTHER
This program will hide one image file inside another.
Working:
Encoder:
First it asks for the two image files. You should enter the filenames with their extensions
Then the program hides the second image in the first one. For this the last nibble (last four bits)
of the first file will be replaced by the first nibble (first 4 bits) of the second image.
The resultant image has higher energy for first image. So the hidden image hardly seen.
During the process it asks for a name for coded image then the name given shouldn't have any extension.
The coded image is saved as BMP instead of JPEG because the JPEG files are compressed images.
So while compressing the hidden image will be affected.
If the two images are not in the same resolution then the program itself will change the resolution of first
image by second.
Decoder:
The image file name given should have extension. The program will do the reverse process of the encoding.
Example photos:
Image 1:
Image 2: (Image to be hid)
Image 3: Encoded image (Image 2 is present inside this)
Decoding image 3 and the decoded images as follows
Download: Hide image.rar
Example :
***** IMAGE HIDER*****
___Program for hidimg one image inside the other image___
_________________________________________________________
---Encode :- 1
---Decode :- 2
Enter your task:1
Welcome to Encoder
Enter the first image file name: vegas_fr.jpg
Enter the second image file name: 54.jpg
Do you want to save the file y/n [y] y
Enter a name for the encoded image: codedvegas
>>
The MATLAB program follows:
-------------------------------------------------------------------------------------------------------------------------------------------------
% Program for hiding an image inside the other
%By
% Mr. vipin.p.nair
% College of Engineering Kallooppara
% vipinpn@yahoo.com
% 06-Nov-2008
%*****************************************************
clc;
disp(' ');
disp(' ***** IMAGE HIDER*****');
disp('___Program for hidimg one image inside the other image___');
disp(' ');
disp('_________________________________________________________');
task = input('---Encode :- 1 \n---Decode :- 2\n Enter your task:');
% select task
if isempty(task)
task=1;
end
if task == 1
% reads two image files
x = imread(input(' Welcome to Encoder\n Enter the first image file name: ','s'));
y = imread(input(' Enter the second image file name: ','s'));
% check compatibility
sx = size(x);
sy = size(y);
if (sx(1) ~= sy(1))(sx(2)~=sy(2))
x=imresize(x,[sy(1),sy(2)]);
end
%
% clearing Ist files lsb bits & moving IInd files msbits bits to lsbits
x1 = bitand(x,uint8(240));
y1 = bitshift(y,-4);
% inserting IInd to Ist file
z=bitor(x1,y1);
% display the first image
figure(1)
image(x);
xlabel(' Ist Image ');
% display IInd image
figure(2);
image(y);
xlabel(' IInd Image ');
% display encoded image
figure(3);
image(z);
xlabel(' Encoded Image ');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name=input('Enter a name for the encoded image: ','s');
if isempty(sav)
name='encoded_temp';
end
name=[name,'.bmp']; % concatination
imwrite(z,name,'bmp');
end
else
% Decoding encoded image
z=imread(input(' Welcome to Decoder\n Enter the image file to be decoded:','s'));
% xo is fist file- obtained by clearing lsb bits, yo is IInd file right
% shifting z by 4 bits
xo=bitand(z,uint8(240));
yo=bitshift(z,4);
% display Ist & IInd image from encoded image
figure(4);
image(xo);
xlabel('Ist Decoded Image ');
figure(5);
image(yo);
xlabel('IInd Decoded Image');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name1=input('Enter a name for the first image: ','s');
name2=input('Enter a name for the second image: ','s');
if isempty(name1)
name1 = 'Ist_temp';
end
if isempty(name2)
name2 = 'IInd_temp';
end
Working:
Encoder:
First it asks for the two image files. You should enter the filenames with their extensions
Then the program hides the second image in the first one. For this the last nibble (last four bits)
of the first file will be replaced by the first nibble (first 4 bits) of the second image.
The resultant image has higher energy for first image. So the hidden image hardly seen.
During the process it asks for a name for coded image then the name given shouldn't have any extension.
The coded image is saved as BMP instead of JPEG because the JPEG files are compressed images.
So while compressing the hidden image will be affected.
If the two images are not in the same resolution then the program itself will change the resolution of first
image by second.
Decoder:
The image file name given should have extension. The program will do the reverse process of the encoding.
Example photos:
Image 1:
Image 2: (Image to be hid)
Image 3: Encoded image (Image 2 is present inside this)
Decoding image 3 and the decoded images as follows
Download: Hide image.rar
Example :
***** IMAGE HIDER*****
___Program for hidimg one image inside the other image___
_________________________________________________________
---Encode :- 1
---Decode :- 2
Enter your task:1
Welcome to Encoder
Enter the first image file name: vegas_fr.jpg
Enter the second image file name: 54.jpg
Do you want to save the file y/n [y] y
Enter a name for the encoded image: codedvegas
>>
The MATLAB program follows:
-------------------------------------------------------------------------------------------------------------------------------------------------
% Program for hiding an image inside the other
%By
% Mr. vipin.p.nair
% College of Engineering Kallooppara
% vipinpn@yahoo.com
% 06-Nov-2008
%*****************************************************
clc;
disp(' ');
disp(' ***** IMAGE HIDER*****');
disp('___Program for hidimg one image inside the other image___');
disp(' ');
disp('_________________________________________________________');
task = input('---Encode :- 1 \n---Decode :- 2\n Enter your task:');
% select task
if isempty(task)
task=1;
end
if task == 1
% reads two image files
x = imread(input(' Welcome to Encoder\n Enter the first image file name: ','s'));
y = imread(input(' Enter the second image file name: ','s'));
% check compatibility
sx = size(x);
sy = size(y);
if (sx(1) ~= sy(1))(sx(2)~=sy(2))
x=imresize(x,[sy(1),sy(2)]);
end
%
% clearing Ist files lsb bits & moving IInd files msbits bits to lsbits
x1 = bitand(x,uint8(240));
y1 = bitshift(y,-4);
% inserting IInd to Ist file
z=bitor(x1,y1);
% display the first image
figure(1)
image(x);
xlabel(' Ist Image ');
% display IInd image
figure(2);
image(y);
xlabel(' IInd Image ');
% display encoded image
figure(3);
image(z);
xlabel(' Encoded Image ');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name=input('Enter a name for the encoded image: ','s');
if isempty(sav)
name='encoded_temp';
end
name=[name,'.bmp']; % concatination
imwrite(z,name,'bmp');
end
else
% Decoding encoded image
z=imread(input(' Welcome to Decoder\n Enter the image file to be decoded:','s'));
% xo is fist file- obtained by clearing lsb bits, yo is IInd file right
% shifting z by 4 bits
xo=bitand(z,uint8(240));
yo=bitshift(z,4);
% display Ist & IInd image from encoded image
figure(4);
image(xo);
xlabel('Ist Decoded Image ');
figure(5);
image(yo);
xlabel('IInd Decoded Image');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name1=input('Enter a name for the first image: ','s');
name2=input('Enter a name for the second image: ','s');
if isempty(name1)
name1 = 'Ist_temp';
end
if isempty(name2)
name2 = 'IInd_temp';
end
Subscribe to:
Posts (Atom)