my code is below but i can not read data from opc to capture image, please help me!!thank you very much!! It show error
Undefined operator '==' for input arguments of type 'struct'.Error in camera_camera_OutputFcn (line 101)if r == 1Error in gui_mainfcn (line 264) feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);Error in camera (line 42) gui_mainfcn(gui_State, varargin{:});function varargout = camera_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;vid = videoinput('winvideo',1, 'MJPG_1280x720');% only capture one frame per trigger, we are not recording a video
vid.FramesPerTrigger = 1;% output would image in RGB color space
vid.ReturnedColorspace = 'rgb';% tell matlab to start the webcam on user request, not automatically
triggerconfig(vid, 'manual');% we need this to know the image height and width
vidRes = get(vid, 'VideoResolution');% image width
imWidth = vidRes(1);% image height
imHeight = vidRes(2);% number of bands of our image (should be 3 because it's RGB)
nBands = get(vid, 'NumberOfBands');% create an empty image container and show it on axPreview
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axes1);% begin the webcam preview
preview(vid, hImage);handles.vid=vid;da = opcda('localhost', 'KEPware.KEPServerEx.V4');connect(da);grp = addgroup(da);itm1 = additem(grp, 'Channel1.Device1.Group1.capture');r = read(itm1);if r == 1 axes(handles.axes2)if ~isfield(handles, 'vid') warndlg('Please do the oncamera first!'); return;endvid=handles.vid;pause(3);data=getsnapshot(vid);imshow(data);savename = strcat('Desktop' ,'hinh', '.jpg'); imwrite(data,savename);axes(handles.axes3);RGB = imread('Desktophinh.jpg');imshow(RGB);I = rgb2gray(RGB);threshold = graythresh(I);bw = im2bw(I,threshold);imshow(bw)bw = bwareaopen(bw,100);se = strel('disk',2);bw = imclose(bw,se);imshow(bw)[B,L] = bwboundaries(bw,'noholes');imshow(label2rgb(L, @jet, [.5 .5 .5]))hold onfor k = 1:length(B) boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)endstats = regionprops(L,'Area','Centroid');threshold = 0.94;stats = regionprops(L,'Area','Centroid');threshold = 0.80;% loop over the boundaries
for k = 1:length(B) % obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k}; % compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2; perimeter = sum(sqrt(sum(delta_sq,2))); % obtain the area calculation corresponding to label 'k'
area = stats(k).Area; % compute the roundness metric
metric = 4*pi*area/perimeter^2; % display the results
metric_string = sprintf('%2.2f',metric); % mark objects above the threshold with a black circle
if metric > threshold centroid = stats(k).Centroid; plot(centroid(1),centroid(2),'ko'); text(centroid(1),centroid(2),'hinh tron'); end if metric < threshold centroid = stats(k).Centroid; plot(centroid(1),centroid(2),'ko'); text(centroid(1),centroid(2),'khong la hinh tron'); end text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',... 'FontSize',14,'FontWeight','bold'); end end
Best Answer