Solving Crossword Puzzles Using Image Acquisition And Data Scraping (Part 2)

Posted on Updated on

In this the second part of the crossword puzzle solver series, we will look at writing to the video input stream. The image acquisition toolbox allows the programmer to configure a function called the UpdatePreviewWindowFcn . Once configured, we can use this function along with others from the vision toolbox like vision.TextInserter and vision.ShapeInserter to add artifacts to the video stream before calling the preview function.

Lets see some code:

vid = videoinput('winvideo', 1, 'YUY2_1280x720');
src = getselectedsource(vid);

vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';

vidRes   = get(vid, 'VideoResolution');
imWidth  = vidRes(1);
imHeight = vidRes(2);
nBands   = get(vid, 'NumberOfBands');
hImage   = image(zeros(imHeight, imWidth, nBands));

setappdata(hImage,'UpdatePreviewWindowFcn',@mypreview_fcn); % configure update udf.

preview(vid, hImage) % display updated stream.

Update Preview UDF code:

function mypreview_fcn(obj,event,himage)
    % display image data.
    tx = vision.TextInserter('Hello World!');
    tx.FontSize = 40;

    set(himage, 'cdata', step(tx, event.Data))

Result: See Hello World! printed in the top left hand corner of the stream.

This functionality will be very important when we get to actually superimposing the solution to the crossword puzzle on the video output stream.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s