Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
image processing with arduino serial communication

Subject: image processing with arduino serial communication

From: Arnab

Date: 21 Apr, 2013 18:38:09

Message: 1 of 1

Hi,I am working for a project about image processing with arduino.Capturing video from webcam and tracking its colour,matlab will send data to arduino.I've done colour tracking and sending data to arduino separately.Now I wanna do this simultanously.The problem is in sending data.
I am using fprintf function sending data.When i press a character it sends data to arduino.I also used fwrite function, it gives this error _
??? Undefined function or method 'combination_not' for input arguments of type 'char'.

 Required logic is to send data when it track the "RED" image.How it can be written.My code is given bellow.Help me please....
%a = imaqhwinfo;
%[camera_name, camera_id, format] = getCameraInfo(a);

   %arduino communication setup
  arduino=serial('COM7','BaudRate',9600); % create serial communication object on port COM4
  fopen(arduino); % initiate arduino communication
% Capture the video frames using the videoinput function
% You have to replace the resolution & your installed adaptor name.
vid = videoinput('winvideo',1);

% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
%start the video aquisition here

% Set a loop that stop after 100 frames of aquisition
    % Get the snapshot of the current frame
    data = getsnapshot(vid);
    % Now to track red objects in real time
    % we have to subtract the red component
    % from the grayscale image to extract the red components in the image.
    diff_im = imsubtract(data(:,:,1), rgb2gray(data));
    %Use a median filter to filter out noise
    diff_im = medfilt2(diff_im, [3 3]);
    % Convert the resulting grayscale image into a binary image.
    diff_im = im2bw(diff_im,0.18);
    % Remove all those pixels less than 300px
    diff_im = bwareaopen(diff_im,300);
    % Label all the connected components in the image.
    bw = bwlabel(diff_im, 8);
    % Here we do the image blob analysis.
    % We get a set of properties for each labeled region.
    stats = regionprops(bw, 'BoundingBox', 'Centroid');
    % Display the image
        %arduino data send
       fprintf(arduinoCom,'%i',sendData); %this will send 5 to the arduino
        fclose(arduino); % end communication with arduino
    hold on
    %This is a loop to bound the red objects in a rectangular box.
    for object = 1:length(stats)
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;
        plot(bc(1),bc(2), '-m+')
        a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
        set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
    hold off
% Both the loops end here.

% Stop the video aquisition.

% Flush all the image data stored in the memory buffer.

% Clear all variables
clear all

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us