目前我正在matlab上进行图像处理项目,我简单地使用网络摄像头捕捉图像,保存图像,使用hough变换处理图像,然后尝试保存图像。当我在转换的图像上使用imwrite函数时,出现此错误:
??? Error using ==> imwrite>validateSizes at 596
Unsupported image datatype 'struct'.
Error in ==> imwrite at 422
validateSizes(data);
Error in ==> findLine at 48
imwrite(tapes,fullImageFileName2);我真的不知道这里发生了什么,但是当摄像头首次拍摄图像时,我使用了imwrite功能,并且保存了没有错误。它是我第二次尝试保存图像,这是我得到此错误的转换图像。任何任何想法?
这是我迄今为止的代码:
vidobj = videoinput('winvideo');
preview(vidobj);
pause(10);
snapshot = getsnapshot(vidobj);
fullImageFileName = fullfile(pwd, 'line.jpg');
imwrite(snapshot,fullImageFileName);
imagesc(snapshot);
imshow(snapshot);
%Load image
tape = imread('C:\Users\Mustafa\Documents\MATLAB\line.jpg');
%Displays the valid values for the Image Processing
iptsetpref ImshowBorder tight
imshow(tape)
%Segment by thresh holding
thresh1 = 100;
tapes = im2bw(tape, thresh1/255);
imshow(tapes)
%Clean up image
%Morphology to assist segmentation
tapes = bwareaopen(tapes,100);%area under 100 pixels
imshow(tapes)
%Clear objects touching the line
%suppresses structures that are lighter than their surroundings and that are connected to the image border.
%(In other words, use this function to clear the image border.)
%tapes = imclearborder(tapes, 26);
%imshow(tapes)
%Find tape
%Find all connected regions
[B,L] = bwboundaries(tapes, 'noholes');
numRegions = max(L(:));
imshow(label2rgb(L))
%Hough transform
[H, theta, rho] = hough(tapes);
peaks = houghpeaks(H, 2);
tapes = houghlines(tapes, theta, rho, peaks, 'FillGap', 50, 'MinLength', 30);
fullImageFileName2 = fullfile(pwd, 'linedetect.png');
imwrite(tapes,fullImageFileName2,'BitDepth',16);