I take down some snapshots from logitech camera and images are stored in array form in pics folder name. Now I want to see those pictures (in png format). So how can i extract iamges from those array. number of images are 20.

 채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 30일

1 개 추천

댓글 수: 6

Naseeb Gill
Naseeb Gill 2015년 12월 30일
Sorry sir but i'm unable to do it. Can you please elaborate it for me or provide me any simple code example to illustrate it. Sorry for inconvenience. Thanks
dinfo = dir('*.png');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
thisimage = imread(thisfile);
figure(); image(thisimage); title(thisfile);
end
It's also not working. I think it's my mistake that I can't explain my problem to you. So, i'm trying again. Thanks for your patience. using camera i takes snapshots and stored them into array form. Code for this is:
vid1 = videoinput('winvideo',1,'RGB24_640x480');
vid2 = videoinput('winvideo',2,'RGB24_640x480');
start(vid1);
start(vid2);
preview(vid1);
preview(vid2);
pics1 = cell(1,10)
pics2 = cell(1,10)
for i = 1: 10
pause(5);
pics1{i} = getsnapshot(vid1);
pics2{i} = getsnapshot(vid1);
end
closepreview(vid1);
closepreview(vid2);
clear ('vid1');
clear ('vid2');
Now arrays are stored in pics1 and pics2 but I want to watch them as .png image and store them as .png only in other folder. how can i do that.
Thanks.
You cannot "watch" PNG images, you can only watch images that have been loaded (possibly from PNG files)
But in any case:
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
for K = 1 : length(pics1)
imshow(ax1, pic1{K});
outfile1 = sprintf('pic1_%03d.png', K);
imwrite(pic1{K}, outfile1, 'png');
imshow(ax2, pic2{K});
outfile2 = sprintf('pic2_%03d.png', K);
imwrite(pic2{K}, outfile2, 'png');
pause(0.25); %or as appropriate
end
And remember to change your code
pics2{i} = getsnapshot(vid1);
to
pics2{i} = getsnapshot(vid2);
Thanks for pointing out my mistake. I solved this problem using following code:
vid1 = videoinput('winvideo',1,'RGB24_640x480');
vid2 = videoinput('winvideo',2,'RGB24_640x480');
start(vid1);
start(vid2);
preview(vid1);
preview(vid2);
pics1 = cell(1,10)
pics2 = cell(1,10)
for i = 1: 10
pause(5);
pics1{i} = getsnapshot(vid1);
pics2{i} = getsnapshot(vid2);
end
for i = 1:10
FileName1 = sprintf( 'pica%d.png',i) ;
fullFileName1 = fullfile( FileName1);
imwrite(pics1{i}, fullFileName1);
FileName2 = sprintf( 'picb%d.png',i) ;
fullFileName2 = fullfile( FileName2);
imwrite(pics2{i}, fullFileName2);
end
closepreview(vid1);
closepreview(vid2);
clear ('vid1');
clear ('vid2');
but now I'm facing a new problem that images store in default folder but i want to save images in predetermined folder say in 'image_folder' folder present on desktop. How can I do it???
project_dir = 'C:\wherever\the\desktop\is\image_folder';
Then
fullFileName1 = fullfile( project_dir, FileName1);
and the corresponding for the second file.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2015년 12월 30일

댓글:

2015년 12월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by