MATLAB: Unable to determine the file format from the file name.

computer visionMATLABmatlab gui

I am using two webcams for stereovision. I am using the following code :
%%set up webcam
leftCam = imaq.VideoDevice('winvideo', 2, 'YUY2_640x480');
rightCam = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480');
objects = imaqfind;
delete(objects)
%%leftCam = imaq.VideoDevice('winvideo', 2, 'YUY2_640x480');
%%rightCam = imaq.VideoDevice ('winvideo', 1, 'YUY2_640x480');
LeftCam.ReturnedDataType = 'uint8';
rightCam.ReturnedDataType = 'uint8';
%%take pictures
%Create initial figure window for fused images
leftImage = step(leftCam);
rightImage = step(rightCam);
dispImage = imfuse(leftImage, rightImage, 'montage');
hFuse = imshow(dispImage);
%Now loop through and capture images
count = 1;
for i = 1:1000
leftImage = step(leftCam);
rightImage = step(rightCam);
dispIamge = imfuse(leftImage, rightImage, 'montage');
if mod(i, 20) == 0
imwrite(leftImage, sprintf('C:\Users\HITESH\Desktop\Matlab\LeftCam%d.jpg', count));
imwrite(leftImage, sprintf('C:\Users\HITESH\Desktop\Matlab\RightCam%d.jpg', count));
dispImage = zero(size(dispImage), 'like', dispIamge);
count = count+1;
end
hFuse.CData = dispImage;
drawnow;
end
%%Clean up
release(leftCam);
release(rightCam);
close all;
I am gettinh the following error:
Warning: Control Character '\U' is not valid. See 'doc sprintf' for control characters valid in the format string.
Error using imwrite (line 426)
Unable to determine the file format from the file name.
I am using MATLAB R2015a
please help!!

Best Answer

output_dir = 'C:\Users\HITESH\Desktop\Matlab';
%%set up webcam
leftCam = imaq.VideoDevice('winvideo', 2, 'YUY2_640x480');
rightCam = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480');
objects = imaqfind;
delete(objects)
%%leftCam = imaq.VideoDevice('winvideo', 2, 'YUY2_640x480');
%%rightCam = imaq.VideoDevice ('winvideo', 1, 'YUY2_640x480');
LeftCam.ReturnedDataType = 'uint8';
rightCam.ReturnedDataType = 'uint8';
%%take pictures
%Create initial figure window for fused images
leftImage = step(leftCam);
rightImage = step(rightCam);
dispImage = imfuse(leftImage, rightImage, 'montage');
hFuse = imshow(dispImage);
%Now loop through and capture images
count = 1;
for i = 1:1000
leftImage = step(leftCam);
rightImage = step(rightCam);
dispIamge = imfuse(leftImage, rightImage, 'montage');
if mod(i, 20) == 0
imwrite(leftImage, fullfile(output_dir, sprintf('LeftCam%d.jpg', count)) );
imwrite(leftImage, fullfile(output_dir, sprintf('RightCam%d.jpg', count)) );
dispImage = zero(size(dispImage), 'like', dispIamge);
count = count+1;
end
hFuse.CData = dispImage;
drawnow;
end
%%Clean up
release(leftCam);
release(rightCam);
close all;
Related Question