Tuesday, December 16, 2008

My Visual Studio Error Puzzle

OK, here’s my small puzzle I came across today.

Start Visual Studio 2008. Select New Project -> Visual C# -> Windows -> Windows Forms Application. WindowsFormsApplication1 seems to be a good enough name. Hit OK.

Now, go to Solution Explorer, right-click WindowsFormsApplication1 and select ‘add Class’. Class1 seems to be a good enough name. Hit OK.

Now, make this class inherit from SoapHttpClientProtocol. For this purpose, add a reference to ‘System.Web.Services’ to References.

Now, decorate this new Class1 with the WebServiceBindingAttribute.
You’ll end up with code as simple as this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;
using System.Web.Services;

namespace WindowsFormsApplication1
{
[WebServiceBindingAttribute(Name = "AsyncRequestSoap",
Namespace = "http://tempuri.org/")]
class Class1 : SoapHttpClientProtocol
{
}
}

The project builds without errors and, if actual code is added to Class1, it will execute without errors. However, if I double-click 'Class1.cs' in Solution Explorer, I would be presented with an error screen like this one:



This seems to be a bug in Visual Studio since it’s obvious that WebServiceBindingAttribute attribute is added to the class and the application will compile and execute regardless of the error screen. Seems to be safe to ignore. However, I did not find clarification on that yet. by . Also posted on my website

Wednesday, December 10, 2008

I'm a scanning developer

I spent a couple of days investigating what this device can do:

3M Full Page Scanner

This smart device is supposed to be able to scan all sorts of passports and other identification documents and retrieve values like names, date of birth, document expiry dates and such. The documentation is not very straightforward and the code samples are in C++ only so it took me a bit of time to figure out how to operate this device programmatically.

First of all, a DocAuth.dll has to be referenced. (There is a bunch of development resources on the CD that comes with the device, and the dll’s are there too). After that, an object of a ReaderClass can be created.

using DOCAUTHLib;
...
r = new ReaderClass();

then the connection to the device has to be established

r.Connect("D72086", "Scanner", "ProcessingDone");

"ProcessingDone" is the comma-separated string that specifies which events will be captured. Other events are “NewDocument ”, “DocumentIdentified ”, etc. After the connection is established, you can subscribe to the scanner events.

r._IReaderEvents_Event_ReaderEvent += new _IReaderEvents_ReaderEventEventHandler(r__IReaderEvents_Event_ReaderEvent);
void r__IReaderEvents_Event_ReaderEvent(string @event){}

In this case, for example, if subscription is made to “ProcessingDone” event only, then whenever a new document is placed into the scanner, it will be automatically scaneed and after that the event will be fired and captured by the function. This might not always be very handy, so I chose to run scans manually. This is done by simply calling

r.DoScan();

To use the device as a simple image scanner, you can instruct it to process the image as a generic image.

r.ForceDocumentProcessing("Generic Image Capture", "");

The image, for some reason, is returned as a string.

string s = r.RetrieveImageItem("Visible", “BMP”); // or JPG, etc.

Alternatively, the image can be saved to disk straight away.

r.RetrieveImageItemAndSave("Visible", “JPG”, @"C:\scan.jpg");

Now, when you want to use this device for automatic retrieval of data from various documents, things become more interesting. Apparently, the list of documents that can be recognised, is stored on the device somewhere. Here is how this can be accessed:

r.RetrieveDatabaseList("");
string dv = string.Empty;
for (int i = 0; i < r.DatabaseListCount; i++)
{
dv = r.get_DatabaseListValue(i);
}

The “database list” is the list of types of documents that are available for recognition. It contains values like “2Line44” or “3Line30”. After the type has been selected, you can access the list of more particular documents belonging to this type in a similar way:

r.RetrieveDocumentItemList(“2Line44”);
string lv = string.Empty;
for (int i = 0; i < r.DocumentItemListCount; i++)
{
lv = r.get_DocumentItemListValue(i);
}

The ‘document item list’ contains values like “Hungarian_Passport”, “Netherlands_Old_Passport” etc. – a lot of them.

Now, after a particular document that we are going to try to read is chosen, we can go and access all the information that the scanner is trying to extract from it.

r.Connect("D72086", "Scanner", "ProcessingDone");
r.ForceDocumentProcessing("2Line44", "Australia_Passport");
r.DoScan();
string fName = r.RetrieveTextItem("@mrz_surname");
string lName = r.RetrieveTextItem("@mrz_givname");

If we’re lucky, the strings will contain proper name of the passport owner.

Now I can go and write a small application that can be used, for example, to add clients to a company database. It will scan the client’s passport and automatically populate fields like name, sex, DOB and a few others.

Overall, it's a fun device to work with. :-)

by . Also posted on my website

I'm a stylish developer

Only today I realized that it's easy to add my own stylesheet to the blog's template so I don't have to format each post which contains code by adding styles to it.

Oh well, I guess you should refer to the blog title, that explains it. Just in case you're a bit like me, though:

  • Simply copy the CSS you want to use to the clipboard
  • In Blogger, go to Template: Edit HTML. In the large textbox in the middle of the page, scroll down to the beginning of the CSS area (it starts with body { ). Just before that line, paste in the CSS you copied
  • Click Save Template
  • (courtesty of How do style my recipe on my blog?)

    by . Also posted on my website