scanner - Dave's Blog

Search
My timeline on Mastodon

Tweet from David_Risney

2015 Oct 14, 2:54
Thor's hammer = Microwave's electromagnet + Arduino + fingerprint scanner. Inventor trolls Venice Beach bystanders: http://www.cnet.com/news/engineer-builds-working-thors-hammer-only-he-can-lift/ …
PermalinkComments

Going Paper-Free for $220 / Steve Losh

2011 May 26, 1:17PermalinkCommentshowto paperless scanner ocr technical

3D scanning with a plain webcam - Boing Boing

2009 Nov 20, 6:43PermalinkCommentsvideo 3d scanner technical

PowerShell Scanning Script

2009 Jun 27, 3:42

I've hooked up the printer/scanner to the Media Center PC since I leave that on all the time anyway so we can have a networked printer. I wanted to hook up the scanner in a somewhat similar fashion but I didn't want to install HP's software (other than the drivers of course). So I've written my own script for scanning in PowerShell that does the following:

  1. Scans using the Windows Image Acquisition APIs via COM
  2. Runs OCR on the image using Microsoft Office Document Imaging via COM (which may already be on your PC if you have Office installed)
  3. Converts the image to JPEG using .NET Image APIs
  4. Stores the OCR text into the EXIF comment field using .NET Image APIs (which means Windows Search can index the image by the text in the image)
  5. Moves the image to the public share

Here's the actual code from my scan.ps1 file:

param([Switch] $ShowProgress, [switch] $OpenCompletedResult)

$filePathTemplate = "C:\users\public\pictures\scanned\scan {0} {1}.{2}";
$time = get-date -uformat "%Y-%m-%d";

[void]([reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"))

$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect();

foreach ($item in $device.Items) {
        $fileIdx = 0;
        while (test-path ($filePathTemplate -f $time,$fileIdx,"*")) {
                [void](++$fileIdx);
        }

        if ($ShowProgress) { "Scanning..." }

        $image = $item.Transfer();
        $fileName = ($filePathTemplate -f $time,$fileIdx,$image.FileExtension);
        $image.SaveFile($fileName);
        clear-variable image

        if ($ShowProgress) { "Running OCR..." }

        $modiDocument = new-object -comobject modi.document;
        $modiDocument.Create($fileName);
        $modiDocument.OCR();
        if ($modiDocument.Images.Count -gt 0) {
                $ocrText = $modiDocument.Images.Item(0).Layout.Text.ToString().Trim();
                $modiDocument.Close();
                clear-variable modiDocument

                if (!($ocrText.Equals(""))) {
                        $fileAsImage = New-Object -TypeName system.drawing.bitmap -ArgumentList $fileName
                        if (!($fileName.EndsWith(".jpg") -or $fileName.EndsWith(".jpeg"))) {
                                if ($ShowProgress) { "Converting to JPEG..." }

                                $newFileName = ($filePathTemplate -f $time,$fileIdx,"jpg");
                                $fileAsImage.Save($newFileName, [System.Drawing.Imaging.ImageFormat]::Jpeg);
                                $fileAsImage.Dispose();
                                del $fileName;

                                $fileAsImage = New-Object -TypeName system.drawing.bitmap -ArgumentList $newFileName 
                                $fileName = $newFileName
                        }

                        if ($ShowProgress) { "Saving OCR Text..." }

                        $property = $fileAsImage.PropertyItems[0];
                        $property.Id = 40092;
                        $property.Type = 1;
                        $property.Value = [system.text.encoding]::Unicode.GetBytes($ocrText);
                        $property.Len = $property.Value.Count;
                        $fileAsImage.SetPropertyItem($property);
                        $fileAsImage.Save(($fileName + ".new"));
                        $fileAsImage.Dispose();
                        del $fileName;
                        ren ($fileName + ".new") $fileName
                }
        }
        else {
                $modiDocument.Close();
                clear-variable modiDocument
        }

        if ($ShowProgress) { "Done." }

        if ($OpenCompletedResult) {
                . $fileName;
        }
        else {
                $result = dir $fileName;
                $result | add-member -membertype noteproperty -name OCRText -value $ocrText
                $result
        }
}

I ran into a few issues:

PermalinkCommentstechnical scanner ocr .net modi powershell office wia

HP All-in-Ones-The Scan Button on the All-in-One Does Not Function When the Printer is Connected to Windows Vista

2009 Jun 20, 9:45"When the scan button is pressed on the product, nothing happens. The scan button does not work correctly." The workarounds are all basically, "don't use that button then." They say their Vista driver doesn't support sending the appropriate event. Lame.PermalinkCommentsvista hp scanner driver lame technical

Coding4Fun : Look at me! Windows Image Acquisition

2009 Jun 20, 9:43How to use the WIA APIs in C#. WIA is Windows API to get images from scanners and cameras. And, as I found out, if you want to use the API in PowerShell try '$deviceManager = new-object -ComObject WIA.DeviceManager'PermalinkCommentsvideo scanner api wia csharp howto programming camera image photo .net webcam technical

Free OCR software? You may already have it... - Jon Galloway

2009 Jun 20, 9:39If you have Office installed you may have an OCR library sitting on your hard drive just waiting to be used via C#...PermalinkCommentsocr microsoft office .net automation scanner camera windows technical

Send URL to Cellphone - QR Encode Accelerator

2009 Apr 14, 9:26

I've made a QR Encode accelerator around Google Chart's QR code generator. QR codes are 2D bar-codes that can store (among other things) URLs and have good support on mobile phones. The accelerator I've written lets you generate a QR code for a selected link and view it in the preview window. In combination with the ZXing bar-code scanner app for my Android cellphone, its easy for me to right click on a link in IE8 on my desktop PC, hover over the QR Encode accelerator to have the link's associated QR code displayed, and then with my phone read that QR code to open my phone's browser to the URL contained inside. Its much easier to browse around in the comfort of my desktop and only send particular URLs to my cellphone as necessary.

PermalinkCommentstechnical boring accelerator android barcode ie8 google qr code

Wikipedia Tools

2007 Sep 12, 6:54I'm visiting Wikipedia more and more recently but I always find myself reading the referenced webpages to get the full context of quotes and for more info. Basically I use Wikipedia as an introduction and a place to look for links. For times when I'm looking for opinions rather than facts I like to use Everything2. No need to check references there.

There's the much hyped WikiScanner tool which reports who has been making anonymous (thought to be anonymous at the time anyway) edits to Wikipedia. Its humorous and interesting in a few cases, but in general I think its stretching to say that because an IP address range is owned by a corporation and someone edited Wikipedia on an IP in that range that you can attribute that edit to that corporation. If I edited Wikipedia I'd probably do a bit of that during my lunch break, but that wouldn't mean that Microsoft wants the Wikipedia pages for Weird Al, Dave Risney, URIs, or whatever else I would edit on Wikipedia changed.

Also, via Everything Is Miscellaneous I found the tool Wiki Dashboard. Wiki Dashboard proxies Wikipedia and on each page shows a timeline view at the top with who made edits and when. Its nice to see a gentle curve down from an initial spike at the beginning for topics you don't imagine to be controversial. As the canonical test page for this service I looked up 'Elephant' the Wikipedia page Stephen Colbert suggested folks vandalize on his show on 2006 July 31st. If you look at the Wiki Dashboard Elephant page you can see a very large spike in edits on that date. That's all I need to see.

As a side note, for the link on Stephen Colbert suggesting folks vandalize Wikipedia I linked to a Wikipedia article. Is it inappropriate to provide info about Wikipedia being vandalized and thus incorrect via a link to a Wikipedia article?PermalinkCommentswikidashboard stephen-colbert wikality wikipedia wikiscanner colbert-report
Older Entries Creative Commons License Some rights reserved.