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

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))
end

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.

Advertisements