Yet Another Hack (YAH)
Its as simple as this:
svn list -R [your svn repo url] | select-string [string to search for]
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.
Crossword puzzles are a very popular pastime in most parts of the western world, and provide a quick means of escape for those on the commute or on break from regular work. The solution to the more interesting puzzles require a fairly good vocabulary and the ability to spot patterns and word arrangements. I recently saw an article on using MATLAB to solve a Sudoku puzzle using image acquisition toolbox and a Sudoku solver algorithm. This series of articles will take a slightly different approach, we will still use the image acquisition toolbox; however, instead of an algorithm to solve the puzzle we will use data scraping form a puzzle website to get the most suitable word for a particular place in the crossword.
The website we will be using to get solutions is One Across
MATLAB is built on the java platform and is able to execute java code written at the command line or inserted in .m files. This feature will be exploited in future articles for doing tasks more suitable to the java toolset.
Example Java and MATLAB code in one .m file
%% import java.net.*; import java.io.*; data = URLEncoder.encode('http://www.oneacross.com/cgi-bin/search_banner.cgi?c0=&p0=r%3Foogle&s=+Go%21+'); url = URL('http://www.oneacross.com/'); con = url.openConnection(); con.setDoOutput(true); wr = OutputStreamWriter(con.getOutputStream()); wr.write(data); rd = BufferedReader(InputStreamReader(con.getInputStream())); while rd.readLine() ~= '' %MATLAB CODE line = ans; end
In part two of this series we will look at using image acquisition to capture a live video feed for the puzzle we want to solve and overlaying the possible solution unto the video feed, stay tuned.