Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Plotting position of text in an image in visual foxpro 1

Status
Not open for further replies.

ravicoder

Programmer
Apr 29, 2006
30
IN
Hello

I have developed a data capture application which captures data from handwritten forms. My requirement is as below:
I need a way to highlight the relevant text field in the form (TIFF image) so that it makes for a more efficient way to capture data instead of scrolling the image to get to the required field - annotations in short.
Can anyone help or guide in how to go about this i.e. plotting coordinates of a portion of text on the image to move a highlight when the user is at the relevant field in the data entry screen?

Thanks
Ravi
 
Hi,

If I understand it you have a TIFF image which you want to show and highlight parts of it when the user enters (gotfocus) a text field ?

Do you a) need to OCR the TIFF to find text in the document or b) do you have coordinates (X,Y) in the image and want to position a highlight ?
For b) a shape positioned on the imagecontrol showing the image might do it. Depending what coordinates you have a calculation coordinates -> pos in image will be neccessary, exspecial if image control is in container.

or
Viscoms imageviewer (not free) should be able to show and overlay :
(OCR is an option, too. Not sure on handwriting)


For those searching and finding this thread :
You press a hotkey and optionally select a region on screen, it does OCR in different languages and puts result to clipboard.
For example : ALT+WIN+E - STRG+C = OCR actual "line" (mousepos), put to keyboard and paste. Its free, portable.
 
As well as Tom's suggestion, there are several on-line OCR tools available. You upload the image (TIFF in this case), and the tool extracts the text, which you then download. At least, that's what they claim. I have no personal experience of these.

I quick Google search threw up these possibilities:


Mike
 
Hi,

. . .
Viscoms imageviewer (not free) should be able to show and overlay :
(OCR is an option, too. Not sure on handwriting)
The viscomsoft product looks nice. But - arrrggh! - I can't understand why folks want to make ordering difficult. They call it "Image Viewer CP Pro SDK ActiveX." Then you look at the purchase page and you see "PDF Viewer" which is more limiting than "Image Viewer" (PDF is a single format, whereas there are lots if Image formats, as you know) and "CP Pro" is not found in any of the product names. Bugs the hell out of me when a product is called one thing on the page to tell you all about it and another thing on the page where you order. Why make people encounter the obvious problem of "is this what I order, because nothing here matches the name they call it elsewhere." People can't figure out this is a problem? It's all on the same page, really, so I guess that makes it more clear, but, still, why one name one place and a different name in another place?
 
Hi Mike,

just to be sure, both tools I mentioned are offline tools.
The viscomsoft product looks nice. But - arrrggh! - I can't understand why folks want to make ordering difficult. They call it "Image Viewer CP Pro SDK ActiveX." Then you look at the purchase page and you see "PDF Viewer" which is more limiting than "Image Viewer" (PDF is a single format, whereas there are lots if Image formats, as you know) and "CP Pro" is not found in any of the product names. Bugs the hell out of me when a product is called one thing on the page to tell you all about it and another thing on the page where you order. Why make people encounter the obvious problem of "is this what I order, because nothing here matches the name they call it elsewhere." People can't figure out this is a problem? It's all on the same page, really, so I guess that makes it more clear, but, still, why one name one place and a different name in another place?
Hello,

I do not know why in the forum its shown as PDF Viewer, the link is hxxps://www.viscomsoft.com/products/imageviewercppro
or maybe hxxps://www.viscomsoft.com/products/imageviewercp
(xx=tt)

PDF Viewer and image viewers are different products.
On the purchase page you find the image viewer pro in the 9th row, a dark blue picture with fotos on it, when you hover over it , you see name , with click you goto order page.

I agree , good software, bad web page
 
I think your strategy is cutting out rectangles of handwriting and OCRing these small parts. Any form where users write over box edges would need reprocessing, but the majority should be doable.

So all you need is a map of the regions in your scans. Hopefully the scans are all aligned well enough but then the problem boils down to cutting a rectangle out of an image, which the gdiplusx library is able to do, no matter if images are JPG, or TIFF.

Then there might be a benefit of not trying to do this mapping yourself and process the whole forms with OCR. It's not the only job of OCR to recognize written letters, they may offer a feature to "understand" forms, if they are "trained" by an empty form.
 
Last edited:
Hi,

If I understand it you have a TIFF image which you want to show and highlight parts of it when the user enters (gotfocus) a text field ?

Do you a) need to OCR the TIFF to find text in the document or b) do you have coordinates (X,Y) in the image and want to position a highlight ?
For b) a shape positioned on the imagecontrol showing the image might do it. Depending what coordinates you have a calculation coordinates -> pos in image will be neccessary, exspecial if image control is in container.

or
Viscoms imageviewer (not free) should be able to show and overlay :
(OCR is an option, too. Not sure on handwriting)


For those searching and finding this thread :
You press a hotkey and optionally select a region on screen, it does OCR in different languages and puts result to clipboard.
For example : ALT+WIN+E - STRG+C = OCR actual "line" (mousepos), put to keyboard and paste. Its free, portable.
Hi Tom

I need a way to know how to plot coordinates an on image to position a highlight on it. OCR is not feasible in this case as all forms are handwritten. I only need to highlight the relevant field in the image. Any tool that can help me plot the x,y coordinates on image would be helpful

If I get this technique, going forward I also thought of showing the highlighted portion as zoomed to a larger size which would be a useful aid in data entry

Ravi
 
Ravi,

You can use a shape to highlight any form section by working with its DrawMode property.

The following demo will get you started.

The coordinates of the various fields are set over the original image, but the image itself can be resized.

No error handling, of course. That will be up to you.

Code:
CREATE CURSOR hwfFields (fieldName varchar(32), x0 int, y0 int, x1 int, y1 int)

INSERT INTO hwfFields VALUES ("Date", 214, 74, 316, 101)
INSERT INTO hwfFields VALUES ("701", 98, 190, 149, 218)
INSERT INTO hwfFields VALUES ("46002", 481, 372, 566, 399)
INSERT INTO hwfFields VALUES ("Observations", 30, 567, 616, 804)

LOCAL hlf AS Highlighter

m.hlf = CREATEOBJECT("Highlighter")
m.hlf.Show()

READ EVENTS

DEFINE CLASS Highlighter AS form

    Height = 568
    Width = 618
    hwfWidth = 0
    hwfHeight = 0
    hwfLeftMargin = 0
    hwfTopMargin = 0
    hwfXYRatio = 1

    ADD OBJECT handwrittenForm AS image WITH ;
        Stretch = 1, ;
        BorderStyle = 1, ;
        Anchor = 15, ;
        Height = 528, ;
        Left = 24, ;
        Top = 20, ;
        Width = 428

    ADD OBJECT highlighter AS shape WITH ;
        DrawMode = 9, ;
        FillStyle = 0, ;
        Visible = .F., ;
        FillColor = RGB(255,255,128)

    ADD OBJECT fieldHighlightning AS comboBox WITH ;
        RowSourceType = 2, ;
        RowSource = "hwfFields", ;
        Style = 2, ;
        Anchor = 8, ;
        Height = 24, ;
        Left = 464, ;
        Top = 68, ;
        Width = 144
        
    PROCEDURE Destroy
        CLEAR EVENTS
    ENDPROC

    PROCEDURE Resize
        This.fieldHighlightning.InteractiveChange()
    ENDPROC

    PROCEDURE Ratios ()

        LOCAL Ratio AS Number, XRatio AS Number, YRatio AS Number

        This.hwfXYRatio = MIN(This.handwrittenForm.Width / This.hwfWidth, This.handwrittenForm.Height / This.hwfHeight)

        IF This.handwrittenForm.Width > (This.hwfWidth * This.hwfXYRatio)
            This.hwfLeftMargin = (This.handwrittenForm.Width - This.hwfWidth * This.hwfXYRatio) / 2
        ELSE
            This.hwfLeftMargin = 0
        ENDIF

        IF This.handwrittenForm.Height > (This.hwfHeight* This.hwfXYRatio)
            This.hwfTopMargin = (This.handwrittenForm.Height - This.hwfHeight * This.hwfXYRatio) / 2
        ELSE
            This.hwfTopMargin = 0
        ENDIF

    ENDPROC

    PROCEDURE handwrittenForm.Init
        LOCAL HTTP AS WinHttp.WinHttpRequest

        m.HTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
        m.HTTP.Open("Get", "https://www.nist.gov/sites/default/files/images/2019/04/27/sd19.jpg", .F.)
        m.HTTP.Send()

        This.PictureVal = m.HTTP.Responsebody

        LOCAL original AS Image
        m.original = CREATEOBJECT("image")
        m.original.PictureVal = This.PictureVal
        
        Thisform.hwfWidth = m.original.Width
        Thisform.hwfHeight = m.original.Height
        Thisform.hwfLeftMargin = 0
        Thisform.hwfTopMargin = 0

    ENDPROC

    PROCEDURE fieldHighlightning.Init

        This.ListIndex = 1
        This.InteractiveChange()

    ENDPROC

    PROCEDURE fieldHighlightning.InteractiveChange

        SELECT hwfFields
        GO (This.ListIndex)

        Thisform.Ratios()

        WITH Thisform.highlighter AS Shape

            .Visible = .F.
            .Left = Thisform.handwrittenForm.Left + hwfFields.x0 * Thisform.hwfXYRatio
            .Top = Thisform.handwrittenForm.Top + hwfFields.y0 * Thisform.hwfXYRatio
            .Width = (Thisform.handwrittenForm.Left + hwfFields.x1 * Thisform.hwfXYRatio) - .Left
            .Height = (Thisform.handwrittenForm.Top + hwfFields.y1 * Thisform.hwfXYRatio) - .Top
            .Left = .Left + Thisform.hwfLeftMargin
            .Top = .Top + Thisform.hwfTopMargin
            .Visible = .T.

        ENDWITH

    ENDPROC

ENDDEFINE
 
You're trying to add highlighted areas into the image for what reason? If you know the regions you want to highlight, why not cut them out of the form and OCR these extracted recftangles? And again, I think OCR software is capable to learn from an empty form what's form text before fillling in and then can concentrate on the filled in forms just the filled in texts.
 
Maybe he wants to show a form where handwritten data has to be extracted by user. So he highlights/zooms part of the form and asks user for input.
I have seen this in another application some years ago where contractforms with handwritten values had to be transfered without errors (that is a 2 humans thing , not OCR :))

So basically : Show form in imagecontrol - hightlight / zoom area - asks user to enter the values he sees in a textbox. Next area,....

Maybe this helps to extract area which can be saved and presented zoomed in a container with imagecontrol (under the textbox for example)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top