5/24/2016

Czur scanner, Still Capture at 2304 x 1728

Figuring out a DirectShow GraphEdit graph and how to use it to perform Still Captures was not easy. But here is a working Graph.


The three key things I learned were:

1. You had to use a more advanced Video Decoder than the generics, because the Images are so large


2. The  output [Pin] for the Czurtek USBVideo Capture element contains a Software Still Capture button


3. You have to use a more advanced Video Encoder to render the capture back into a file format


The end result is when the graph is [Run] by pressing the green triangle [Play] button, you can right click the output pin on the Czurtek to Take a [Snap Shot] which is then piped out the advanced video decoder through the advanced video encoder and stored in a file. Due to application/operating system mem/disk caching the file isn't actually updated with a thumbnail until its closed by stopping the graph by pressing the red [Stop] button.

The result is a jpeg file with 2304 x 1728 pixel dimensions, in a quite small space of about 800 kb



Although I have on occasion triggered a guideline projection on a captured image, I have not been able to do so consistently.. probably due to a gap in my understanding of how that is being triggered.. and perhaps because there isn't a control in the graph for specifically setting it.

This appears to be close, but not the maximum "advertised" resolution of the scanner. One more level is indicated in the USB Descriptors but I have not been able to determine if there is a hardware/software limitation in my setup or the scanner simply becomes unstable when pushing to those limits.

Regardless the image captured above is very high resolution and clear.. and speaks to the "possibilities" this hardware brings.

Here is a direct link to the actual jpeg file, you can download it and zoom in to inspect the level of detail.

Still-Capture-at-2304x1728.jpg

One thing stiring in my mind is that the work flow for making ebooks from scans is rather cumbersome. Really the APIs and tools are more like Linear Video Editing. and Microsoft banished the Still Capture features of their API to the 'Movie Maker' venue.. which got me to thinking of camera rolls and Google Picasa and their struggles with things like Adobe Lightroom to "manage" all these images.. which are really digital photographs. We trust the timecodes and order are being preserved.. lest they tumble like a stack of unruly photographs to the floor in such disarray as to never be reassembled in order.

So on the edge of my thoughts are.. perhaps a Book "binding" program that treats scanning as a sequential "Movie" frame by frame.. enabling you to save projects and "half complete work" in  "Project file" format that is a sequential set of frames like a photoroll..but also handled like a Movie.. in which you can Non-Linearly Edit if you like.. re-shoot footage and splice and re-splice until the final product is ready for distillation and "publication" or saving in its final form. In such a mindset.. the PDF would become a type of Interleaved "A/V" file without the "A" but if you should choose perhaps thats not a bad idea either.. since Visual Books are often translated into Audio books.. and I believe PDF files now have some form of Speech or Audio inclusion capabilites.

In the bigger picture.. something like Sony Vegas Movie Editor.. with all its filters for Chroma correction, Rotation, Masking and Dewarping.. don't seem so far out of place.. and also could become truly useful tools when editing an ebook.. we just need to "discover" an export feature from a Movie Maker program for publishing in PDF or ePub format.

For the more casual of users however a simpler sequential capture and bind workflow would be simpler and faster to follow. Say for the office person who just wants to scan a bunch of paperwork, shred it and save the PDF file to a legal form.. perhaps to be OCR'd later.. perhaps not.. but OCR and Indexing by OCR are not necessarily a required step in capturing books and loose leaf materials in a digital format.

One of the really great things this exercise teaches.

Is that this was all done using the USBVideo Class, which is supported by every operating system platform that supports USB 2.0 devices. There is nothing special about this technique. It was instructive of course how "limited" the default original generic video decoders and encoders "were" and that you had to use a component or library that "allowed" or took into account the "possibility" of really "large" image sizes.

Back in the day.. megapixel images just weren't "normal" and for an API thinking in terms of low res webcams streaming over slow dial up internet connections.. the expectations and "limits" were just set too low. In order to embrace this type of evolutionary device.. more modern code libraries will have to be used.

Unfortunately I think that also means simpler "shrink wrap" software programs we might already want to use to help capture and build documents.. might need to either take these into account.. or something that is actually built for edocument capture and publishing, like Adobe PDF programs may be where we have to go until -- that "Movie maker" Non-Linear Book binding program comes along.

In the mean time however we can all pretend to be the great Messier Star Catalog and map out our Globular Clusters of documents on our hard disks ourselves.

5/19/2016

Czur scanner, the USBVideo Class

Its hard to get a handle on how to communicate with the Czur USBVideo Class. Analyzing the pcap in Wireshark reports bcdDevice: 0x0100. The USB Video Class 1.1 example doc from 2005 make understanding the USB traffic somewhat easier.


Basically USB has many standards, which add up to an implementation in which a USB Host (the PC) communicates to a USB Device (the USB Video device) over a cable in a particular format.

The actual signalling involved on the USB wire is mostly ignored, since the operating system comes minimally equipped with device drivers for exporting a user program side interface that can be used to discover and send and receive "higher" protocol or "Class" protocol messages with a USB connected device.

Each "Class" of device has a set of "procedures" that roughly are designed to discover, query and setup that type of USB device using these "Class" protocols. They operate with a set of "assumptions" that are safe to make when you know your dealing with a particular device that belongs to that Class type.

A mouse or keyboard for example belong to the HID (Human Interface Device) "Class" and they are one of the simplest communications models to program.

A webcam belongs to the USB Video "Class" and is a lot more complicated.

The standard USB precursor to "Class" type communications first has to figure out which class the USB device belongs to, then load that class driver into memory and begin using Class protocols for it.

When monitoring or "sniffing" or "capturing" USB traffic by branching or inserting a "Tap" in the path between the operating system and the USB port driver. Everything comes out linearly, one after the other.. but each protocol message, read and write of a Class protocol message is conducted with a purpose in mind that serves the standard setup and operating procedure for that USB Class device.

The USB Specifications for the USB Class are very "wordily" explained.. in a somewhat backwards fashion beause the sentences while in English follow an Adjective or Description, before Object or Noun format. Which might be because historically "standards" originated in France and the language structure there is different than in other countries. Over time this has become the "normal" way of writing a standards document and makes it somewhat difficult for less experienced people to contemplate. -- this is not unique to USB standards, many things in Science and Art begin with a staged preamble regarding what will be talked about before getting around to discussing the subject matter. -- as a matter of course it appears "Indirect" and taxing on the casual "commoner listener" since they are usually less patient and more focused on the task at hand, not ten years from now.

But moving on.. with the task at hand.

The widely available USB_Video_Example 1.1.pdf  document explains the "model" or assumed idealistic example of a webcam and what each linear procedure across the USB bus is doing after the USB Class driver is loaded and begins the task of setting up the device for communications. It also explains why things are they way they are and what purpose each call serves.


This is proving a useful document for understanding the Czur scanner.


Appearing as a USB Video 1.0 Class device, it has the standard interfaces one would expect with a few differences to account for more interfaces since the Czur scanner device also supports a few different compression and uncompression frame formats and methods of delivering those frames of information over USB.

Its been a really great motivation for me to better understand USB communications at the Class level which simpler classes rarely motivate one to do.

I suspect however that raw Class calls do not map directly back to the way the Native Czur scanner software communicates with the Czur scanner.

Rather, on Windows there is a long history going back to Windows 98, then ME, 2000, XP, Vista, then Win7, 8 and now 10 of declaring then abandonning various programming languages styles, APIs and program build tools.

Currently the USB Video Class came into being around the time of Visual C/C++ and the Video for Windows API era. That was supereced by the STI/WIA era which more or less emulated or copied the more widely used and still popular dedicated scanner API for many operating systems called TWAIN.

Then in Vista Microsoft re-thought, complicated, things by making WIA persona nongrata.. and removed most of the functionality for supporting the USB Video Class - Still Image support and banishing it to the DirectX/DirectShow "game development API".. because scanning is like "First Person Shooting, I guess? "

Which was scheduled for deprecation or dissolution by the Windows Media Foundation classes (for Movie making) but never quite got off the ground.

In the meantime.. C/C++ which replaced C/ASM development on old Windows, was itself depopularized or demonized by "Managed Code" after the altercations with Sun/Java and the emergence of the CLR and .NET family of languages.. but somehow.. they never bothered to port "legacy useful APIs" so they left it as an "exercise" for individual programmers themselves to "implement" Wrappers to produce code "Bindings" between legacy C/C++ libraries and .NET (so why is it we're doing .NET if its not good for anything ??)

So much has been left behind and so many people have left Microsoft in the last decade.. not to mention the little mobile problems.. that few outside MVPs outside the company seem to recall how to implement examples for things like AVCAP2.exe which included perhaps the oldest and only example of  using the USB Video class for Still Image capture.

So...

Its speculation.. but using DirectShow GraphEdit (a Filter "programming" tool) to prototype using the Microsoft USBVideo.sys Class driver to communicate with the Czur scanner.. a "live" Rendering Window could be created.


Unfortunately a "functional" Still Image protype could not be made to "fire" or snag a full frame image because Microsoft deprecated the USBCmdButton API before it got very far.. and refer developers to instantiating the USB Video Controller and manually firing or hooking the device hardware interupt to actually "activate" the Still Image function on the scanner.

Its all rather frustrating.

The latest developments seem to be more people prefer using a Linux derived Kernel driver on the latest versions of Windows operating system Kernels because of the schizophrenic incomplete API hell developers appear to have to go through to create an application. [But] because Windows Kernel drivers must be signed, and must be signed by a cross signed code-developers signing certificate that costs hundreds of dollars a year to maintain.. the windows development for kernel drivers is grinding to a halt. -- I think in family dynamics this is called a "Habitual Dysfunctional Situation"


Its speculation, however the Czur native software appears to include several software development kit components or piece of frameworks. Notably avcodec, avdevice, avfilter, avformat, avutil -- would point towards a possible DirectShow or WMC connection for invoking the USB Video Still Image capture function. .NET libraries are no where to be found.

Video Lan Client or VLC is notable in that it can [also] invoke the USBVideo.sys Class library and acquire Live video at various resolutions..(invoking Dshow:// directly) but while it can capture Snapshots from its live feed.. it does not appear to have any built-in functionality for invoking the native USB Video Class  Still image capture method.. which in theory should be much clearer and more stable.




5/18/2016

Czur scanner, Still Image Method #2

USBPcap and hand decoding the last bytes from the [Still Image Frame (3)] subtype:

frame.protocols == "usb:usbvideo"

usbvideo.streaming.descriptorSubType == 3

00: if still method 2 this field is set to zero
04: number of Image Size patterns of this format: n

80:02: wWidth  (1)  32770 or 640
e0:01: wHeight (1)  57345 or 480

00:09: wWidth  (2)   9    or 2304
c0:06: wHeight (2)  49158 or 1728

40:06: wWidth  (3)  16390 or 1600
b0:04: wHeight (3)  45060 or 1200

20:0a: wWidth  (4)  8202  or 2592
98:07: wHeight (4) 38919  or 1944

00: number of Compression patter of this format 0

Which to me is in agreement with the UVC Spec on Page 15

Universal Serial Bus
Device Class Definition
for
Video Devices
Revision 1.1
June 1, 2005

Method 2 – 

If the device supports higher-quality still images, it has the option of streaming still-image-specific packets across the active video pipe. 

In this case, the host software will temporarily suspend video streaming, select the optimal bandwidth alternate setting based on the still probe/commit negotiation (subject to bandwidth availability), send a VS_STILL_IMAGE_TRIGGER_CONTROL Set request with the "Transmit still image" option (see section 4.3.1.4, "Still Image Trigger Control"), and prepare to receive the still image data. 

The device transmits the still image data marked as such in the payload header (see section 2.4.3.2.2, "Sample Isochronous Transfers"). Once the complete still image is received, the host software will then revert back to the original alternate setting, and resume video streaming. 

The resolutions are less than final images, but I "guess" this is due to using OpenCV mat functions to remap the pixels into a slightly larger final matrix as JPEG images.

Windows 7 no longer has support for WIA access to UVC video sources, however XP still did.. so it might make sense to see if WIA on XP can access a still image function exposed by the native UVC interface.

Update - while XP did identify the scanner as a USB device with Video and Audio, the Scanner app in XP would not take a picture.

I don't actually know of any Windows software that will make use of the STI capture feature in Windows 7

Possibly the Camera app in Windows 8/8.1 will looking forward.. something to test later today or tomorrow.


5/16/2016

Czur scanner, unexpected detour

Used VLC and targeted the scanner as a capture device. The results were surprising:

Figure 1. Pedestal triggered image scan

Not sure how I triggered the Laser guides to appear and become part of the image scan, they can obviously be chroma-key removed, and extracted to contruct a mesh for de-warping.

Finding software that can make use of the captured images maybe more of a challenge.

Some like Booksorber also seem to already have "flattening" algorithms that would not make use of the guidelines.

Although, after the images are captured, it would be assumed you could "import" them into the native software provided with the scanner and corrected and ocr'd then bound into an ebook.



And its somewhat instructive to compare $2400 software to that made available with the Czur

Although I still find the Quality of the native Czur software for the PC simply amazing.
Zooming in on a single image reveals its in focus, has fine detail and really looks good.

4:40 pm update

Browsed the native software directory and found libraries for VLC and the BSD Licensed OpenCV project, as well as familar libraries for Abby FineReader.. all best in Class quality components.

The OpenCV for "Open Computer Vision" project is known to have fairly technical library functions for both capture of images and manipulation, including "undistort" and "dewarping" functions.

So that further supports the "idea" that the scanner is a good quality camera and acquistion platform, but "flattening" of the images takes place within the native software provided.

The selected libraries are well chosen for porting the software to other platforms like Linux and Mac OSX since they exist on those operating systems as well.

All very encouraging news.

More than ever I wish they would release a simplified SDK for plugging the device into existing scanning tools on each operating system. I don't think existing tools would compete with the native software, but would quickly expand the range of useful options for people who don't have time to learn the native software, or would rather use the scanner in a way other than it was intended.

The one or two functions that would be most useful would be simply hi-res default image capture that the current native software uses to capture and image and offload that to the PC. The images seem to come in at about 3 MB and in the JPEG format. Also the function that captures the same image with Laser Guidelines would be very useful.


Czur scanner, USBpcap and Iso transfers


I moved on from USBSnoopy to USBpcap and Live Wireshark decode. The results were encouraging.

USBpcap for Windows XP, 7, 8

It was a lot simpler to setup, no reboot was required.

basically download and run, then run again to identify the USB Hub to monitor and enter the pcap file name to save the results, the capture begins, CTRL+C to end

to "live" capture, its very similar

C:\Program Files\USBPcap>USBPcapCMD.exe -d \\.\USBPcap3 -o - | "C:\Program Files
\Wireshark\Wireshark.exe" -k -i -
where USBPcap3 is the "name" assigned to the USB Hub to be monitored when running the USBpcap command by itself to list available Hubs

as a Host the PC detects when a new device is plugged in, then interrogates it for its capabilites automatically


I believe the images are transfered Isochronously since I have made triggers and only seen Isochronous transfers, further when the USB bus was overloaded the Images saved to the PC are interwoven with parts from other images. No Bulk transfers were observed.

This reverses my earlier assumption that flattening was occuring in the device and leads me to think flattening takes place within the image.. but where the laser guideline information is stored I cannot say.

One capture alluded to [ Siri A9 UVC chipset  6333 ] which is every interesting if A9 and Siri happen to have something in common with Apple products. -- curious side note, I got an unusal answer from an inquiry about supporting the Czur scanner in other existing scanner software.. to which the answer was.. not now, working on adding Apple iPhones as capture devices. I thought nothing of it.. but now I wonder if that brief answer might be a result of the chipset already in the Czur scanner.

5/14/2016

Czur scanner, working on an SDK

No news at present, but been exploring Windows device driver signing and enabling USBSnoopy to capture communications with the Scanner over USB. I'd like to document it well enough that a few simple tools could be created for enabling more software development with it on Windows and other operating systems.

This won't replace an official sdk if it were ever to be released.. but it could serve in the interim.

1:53 am - a little progress

The old Windows 98/XP debug program [SnoopyPro] proved somewhat cranky and difficult to get working. Many people seemed to think it would not run on Windows 7 x64.. turns out it will run.


The caveats come from misunderstanding much of the Microsoft documentation regarding the boot time F8 option to 'disable' signed driver enforcement.

Basically they said to 'disable' enforcement.. not that you could "load" unsigned drivers.

For example, to get Snoopy to work. I had to install the Windows SDK and DDK to get the tools to create a Self-Signed Code Signing Certificate, perform an [embedded] signing of just the USBSnoop.sys and USBSnpys.sys files and [pre-install] them by copying them to windows\system32\drivers.

Then run the [SnoopyPro.exe] separately and choose [not to] Unpack the drivers again.

See in the old days (and today) you had a choice of installing drivers from a binary, or packaging them separately with an INF file so the PnP service could inventory and load them for you when a device was plugged in.. this was not so normal for debugging software.. so they tended to perform the driver "injection" manually and carried the drivers inside themselves.. fast forward to Windows Vista days.. and signed driver enforcements.. and you had to make sure to [embed-sign] drivers that were to be carried inside the binary and deployed "at will" upon a system.

It didn't help the documentation provided [only] alluded to embedded signing requirements and proceeded to "document" in an old Word doc format with an example that did not explicitly demonstrate the signing procedure.. so your left with.. hints and innuendos.. and well.. "typical" ms documentation.

Normal outsiders "assumed" this meant you could disable driver "must-be-signed" enforcement

Microsoft insiders "meant" you could disable enforcement of "properly" signed drivers

The difference being, if you used a self-signed cert, its illegal "normally" but legal if you disable enforcement.

The problem being, if you have a driver that is "improperly" signed, perhaps a bad intermediate or cross sign cert.. you could get that driver to work with F8 or a boot option.. and "think" you got away with something when you really did not. -- the reality being.. it was signed.. just not "properly" signed.

[Next] you have to "Unblock" the [Silent] Executeable "Block" placed on files identified as coming from the Internet.. basically right-click SnoopyPro.exe then Properties and [Unblock].. otherwise running it would silently deny complete access to the system.. even if run as Administrator.

[Finally] you have to run in compatibility mode with [Windows Vista (Service Pack 2)] as Administrator.. and the program will start and be ready to capture packets.

There is no good documentation on how to use the program, but basically you F2 to display currently detected USB devices, select the one that says Czurtek and right-click to Install and Install service.

This preassumes you already installed the Snpys bridge > File > Install service and you [did not Unpack drivers, because you copied the "signed ones" into place]

Also you had already imported the signed certs for CA and self, and rebooted to press F8 and choose not to "enforce" security for improperly signed drivers -- see the "key" is the drivers are "signed", but they are not signed "properly" -- if they were not signed at all.. they are just not loaded and no warning messages are provided.

This all to avoid the $100+ requirement to get a crossed signed code signing certificate and to collect URB packets on my currently installed Window 7 x64 machine with the Czurtek drivers and software communicating with the scanner.

[With all of that "Preamble Ramble" the actual use is, all the setup did was insert a bridge driver for copying packets "sneaked out" from the driver stack for the connected device by the "filter" driver acting as a man-in-the-middle between the device and the operating system].. so once its built.. you basically [unplug/plug] the scanner into the PC with the usb cable and the SnoopyPro program opens a new dialog window inside its parent window and begins "capturing" packets.

I think its suppose to interpret them on the fly.. but it did not for me.. the window remained empty, but the status bar across the top of the new window indicated packets were being captured, a pause button and a stop button. I ran the Czur software then let it capture for a while and stopped it and used the File menu option from SnoopyPro to save the packets to a file. Then re-opened the log in SnoopyPro and it "interpreted the packets" as shown below:


There are two "devices" for the Czur scanner, one is the image device the other is a sound device. Or that is what the Windows Device Manager identifies them as.. how the software communicates with them after they are classified is vendor specific.

I can see that it appears a number of [USB Control] type packets are being exchanged, and witnessed a Bulk transfer.. possibly related to initating a snapshot in the software to capture an image.

But the interpretation of the communications is far from complete.. I am not even sure that SnoopyPro would be the best way of capturing and interpreting the packets.

I had thought to use it with USBrobot to replay the communications to test possible function calls for a users API.. but I have a lot of doubts about the stability and complete-ness of the data capture.. the Bulk transfer seemed to decode somewhat incompletely.

I am beginning to think if this were a Tape Media Changer USBSnoopy might be okay.. but there might be better tools for a more reliable analysis.. USBpcap looks interesting.. and then Wireshark could be used with LUA to intepret the packets.. even added to.. to test and develop an API that could be used in many operating systems.

Mostly this test was for completness sake.. I didn't want to over look a potentially easier way of capturing data and interpreting the results.

5/12/2016

Annual checkup

by the numbers
Total Cholesterol
126 mg/dL

LDL Cholesterol
47 mg/dL

HDL Cholesterol
69 mg/dL

Triglycerides
49 mg/dL