Acquiring a Single Image in a Loop

Embed Size (px)

Citation preview

  • 7/28/2019 Acquiring a Single Image in a Loop

    1/3

    United States Contact Us Store Search

    Create Account Log In

    Products & Services Solutions Academia Support User Community Events Company

    Trial Software Product Updates ShareDocumentation CenterDocumentation Center

    Search R2013a Documentation Search

    Image Acquisition Toolbox Image Acquisition Toolbox Examples

    Acquiring a Single Image in a LoopAcquiring a Single Image in a Loop

    This example shows how to use the GETSNAPSHOT function and provides some tips for efficient use. The GETSNAPSHOT function

    allows for quick acquisition of a single video frame.

    Set up the Acquisition Object

    Most interaction with Image Acquisition Toolbox is done through a video input object. These objects are created with the VIDEOINPUT

    command. This example uses a webcam that is accessed through the toolbox's "winvideo" adaptor.

    vidobj = videoinput('winvideo');

    Acquire a Frame

    To acquire a single frame, use the GETSNAPSHOT function.

    snapshot = getsnapshot(vidobj);

    % Display the frame in a figure window.

    imagesc(snapshot)

    Acquire Multiple Frames

    Acommon task is to repeatedly acquire a single image, process it, and then store the result. To do this, GETSNAPSHOT can be called in aloop.

    for i = 1:5

    snapshot = getsnapshot(vidobj);

    imagesc(snapshot);

    end

    Accelerating the pace of engineering and science

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://www.mathworks.com/help/imaq/examples/index.htmlhttp://www.mathworks.com/help/imaq/index.htmlhttp://www.mathworks.com/help/documentation-center.htmlhttp://www.addthis.com/bookmark.php?v=250&pubid=mathworkshttp://www.mathworks.com/support/web_downloads_bounce.html?s_cid=1008_degr_docdn_270055http://www.mathworks.com/programs/bounce/doc_tryit.htmlhttp://www.mathworks.com/company/http://www.mathworks.com/company/events/http://www.mathworks.com/matlabcentral/http://www.mathworks.com/support/http://www.mathworks.com/academia/http://www.mathworks.com/solutions/http://www.mathworks.com/products/https://www.mathworks.com/accesslogin/login.do?uri=http://www.mathworks.com/help/imaq/examples/acquiring-a-single-image-in-a-loop.htmlhttps://www.mathworks.com/accesslogin/createProfile.do?uri=http://www.mathworks.com/help/imaq/examples/acquiring-a-single-image-in-a-loop.htmlhttp://www.mathworks.com/store/default.do?s_cid=store_top_navhttp://www.mathworks.com/company/aboutus/contact_us/http://www.mathworks.com/company/worldwide/
  • 7/28/2019 Acquiring a Single Image in a Loop

    2/3

    Timing Implications

    The GETSNAPSHOT function performs a lot of work when it is called. It must connect to the device, configure it, start the acquisition,

    acquire one frame, stop the acquisition, and then close the device. This means that the acquisition of one frame can take significantly

    longer than would be expected based on the frame rate of the camera. To illustrate this, call GETSNAPSHOT in a loop.

    % Measure the time to acquire 20 frames.

    ticfor i = 1:20

    snapshot = getsnapshot(vidobj);

    end

    elapsedTime = toc

    % Compute the time per frame and effective frame rate.

    timePerFrame = elapsedTime/20

    effectiveFrameRate = 1/timePerFrame

    elapsedTime =

    21.2434

    timePerFrame =

    1.0622

    effectiveFrameRate =

    0.9415

    The next example illustrates a more efficient way to perform the loop.

    Using Manual Trigger Mode

    You can avoid the overhead of GETSNAPSHOT described in the previous setting by using the manual triggering mode of the videoinput

    object. Manual triggering mode allows the toolbox to connect to and configure the device a single time without logging data to memory. Thismeans that frames can be returned to MATLAB with less of a delay.

    % Configure the object for manual trigger mode.

    triggerconfig(vidobj, 'manual');

    % Now that the device is configured for manual triggering, call START.

    % This will cause the device to send data back to MATLAB, but will not log

    % frames to memory at this point.

    start(vidobj)

    % Measure the time to acquire 20 frames.

    tic

    for i = 1:20

    snapshot = getsnapshot(vidobj);

    end

    elapsedTime = toc

    % Compute the time per frame and effective frame rate.

    timePerFrame = elapsedTime/20

    effectiveFrameRate = 1/timePerFrame

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/28/2019 Acquiring a Single Image in a Loop

    3/3

    % Call the STOP function to stop the device.

    stop(vidobj)

    elapsedTime =

    1.4811

    timePerFrame =

    0.0741

    effectiveFrameRate =

    13.5031

    You can see that the elapsed time using manual triggering is much smaller than the previous example.

    Cleanup

    Once the video input object is no longer needed, delete the associated variable.

    delete(vidobj)

    See also IMAQHELP, VIDEOINPUT, IMAQDEVICE/GETSNAPSHOT, IMAQDEVICE/START, IMAQDEVICE/STOP

    IMAQDEVICE/TRIGGERCONFIG.

    Was this topic helpful? Yes No

    Try MATLAB, Simulink, and Other Products

    Get trial now

    Join the conversation

    Preventing PiracyPrivacy PolicyTrademarksPatentsSite Help 1994-2013 The MathWorks, Inc.

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://www.mathworks.com/help.htmlhttp://www.mathworks.com/company/aboutus/policies_statements/patents.htmlhttp://www.mathworks.com/company/aboutus/policies_statements/trademarks.htmlhttp://www.mathworks.com/company/aboutus/policies_statements/http://www.mathworks.com/company/aboutus/policies_statements/piracy.htmlhttp://www.mathworks.com/programs/bounce_hub_generic.html?s_tid=mlc_twt&url=http://www.twitter.com/MATLABhttp://www.mathworks.com/programs/bounce_hub_generic.html?s_tid=mlc_fbk&url=http://www.facebook.com/MATLABhttp://www.mathworks.com/programs/bounce_hub_generic.html?s_tid=mlc_glg&url=https://plus.google.com/117177960465154322866?prsrc=3http://www.mathworks.com/company/rss/index.htmlhttp://www.mathworks.com/programs/trials/trial_request.html?prodcode=IA&eventid=1086459872&s_iid=doc_trial_IA_footer