[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

More Specific OCR Problem

Posted on 2003-11-18
5
Medium Priority
?
716 Views
Last Modified: 2007-12-19
Ok. Let me try this, it may be easier....

I've got this C++ Project (still) that is a commercial OCR Engine. I am trying to re-write it with the built in API into C#. It heavily uses pointers and other things I'm a bit unfamiliar with. I'm currently stuck on this... (This is the C++ Code - Original)

                  TOCRResults = (TOCRRESULTS *)malloc(ResultsInf);
                  cout << "TOCRResults " << TOCRResults << endl;
                  if ( TOCRResults ) {

                        // Retrieve the results

                        status = TOCRGetJobResults(JobNo, &ResultsInf, TOCRResults);
                        if ( status != TOCR_OK ) goto ABORT;
                        cout << "Num Items: " << TOCRResults->Hdr.NumItems << endl;

                        // Display the results

                        printf("\t\t");
                        for (ItemNo = 0; ItemNo < TOCRResults->Hdr.NumItems; ItemNo ++ ) {
                              if ( TOCRResults->Item[ItemNo].OCRCha == '\r' )
                                    printf("\n\t\t");
                              else
                                    printf("%c", TOCRResults->Item[ItemNo].OCRCha);
                        }
                        printf("\n");
                        free (TOCRResults);

I hope that doesn't come out messy..anyway..
my Current attempt at C# Reindition is as follows...
                  TOCRResults = new TOCRResults();
                        status = API.TOCRGetJobResults(JobNo, ref ResultsInf,TOCRResults);
                        if ( ResultsInf > 0 )
                        {

                              TOCRResults = new TOCRResults();
                              TOCRResults.IsTrue = true;            

                              Console.WriteLine("Results Inf: " + ResultsInf.ToString());
                              Console.WriteLine("Results SizeOf: " + Marshal.SizeOf(TOCRResults));
                              if ( TOCRResults.IsTrue )
                              {
                                    // Retrieve the results
                                    status = API.TOCRGetJobResults(JobNo,ref ResultsInf, TOCRResults);
                                    // Display the results
                                    TOCRResultsItem[] Item = new TOCRResultsItem[ResultsInf];
      
                                    TOCRResults.Hdr.NumItems = Item.Length;
                                    for(int temp = 0;temp <=Item.Length-1;temp++)
                                          TOCRResults.Item[temp] = Item[temp];
                              TOCRResults.Item = Item;
                                    Console.WriteLine(Item.ToString());

                                    Console.WriteLine("\t\tTest");
                                    for (ItemNo = 0; ItemNo < TOCRResults.Hdr.NumItems; ItemNo ++ )
                                    {
                                          if ( TOCRResults.Item[ItemNo].OCRCha == '\r' )
                                                Console.WriteLine("\n\t\t");
                                          else
                                          {
                                                Console.WriteLine(TOCRResults.Item[ItemNo].OCRCha);
                                                Console.WriteLine(Item[ItemNo].OCRCha.ToString());
                                          }
                                    }
                                    Console.WriteLine("\nLast Line");
                              }
                              else
                              {
                                    Console.WriteLine("Failed to allocate memory for results\n");
                              }
                        }
                        else
                        {
                              Console.WriteLine("No results found\n");
                        }


------------------

The Structs for the "TOCRResults" object or class are as follows as well..
C++
---------------------------
typedef struct tagTOCRRESULTSITEM
{
      unsigned short      StructId;
      unsigned short      OCRCha;
      float                  Confidence;
      unsigned short      XPos;
      unsigned short      YPos;
      unsigned short      XDim;
      unsigned short      YDim;
} TOCRRESULTSITEM;


typedef struct tagTOCRRESULTS
{
    TOCRRESULTSHEADER      Hdr;
    TOCRRESULTSITEM            Item[1];
} TOCRRESULTS;
-----------------------------

C# Recreation
----------------------------------------
[StructLayout(LayoutKind.Sequential)]
public struct TOCRResultsItem
{
      public int            StructId;
      public ushort      OCRCha;
      public float      Confidence;
      public ushort      XPos;
      public ushort      YPos;
      public ushort      XDim;
      public ushort      YDim;
}
[StructLayout(LayoutKind.Sequential)]
public struct TOCRResults
{
      public TOCRResultsHeader      Hdr;
      //[MarshalAs(UnmanagedType.ByValArray)]
      public TOCRResultsItem[]      Item;
      public bool IsTrue;   //attempted member for boolean operation in Main.cs file ..didn't really help anything.
      public int Null;  // this was an attempt to pass a '0' through the GetJobResults instead of the object TOCRResults, which didn't seem to bode well with C#, but worked fine in C++, it too was useless...
-------------------------------

The function/method call is as follows..

      [DllImportAttribute("TOCRdll")]
      public static extern int TOCRGetJobResults(int JobNo, ref int ResultsInf, TOCRResults Results);
------------------------

I know this is rather vague, but it's a several file Project, and I can't distribute the source code for the engine. My problem is that It simply won't return anything, the ResultsInf variable 'DOES' Work properly (Returning the number of characters in the image file I try to process) but after that, nothing seems to work right. Can anyone help me? I can provide more info if I need to.
      
}
0
Comment
Question by:derekthornton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
stone123 earned 2000 total points
ID: 9774756
the ResultsInf variable works but the Results doesn't. What is the difference between the two variables?

the first one is an integer, a primative type. the other is a user-defined struct type. When your function returns a primative type, it simply copy the value. the memory format and size of int type should be the same in both native C/C++ and C#. (just my wild guess).

However, when it comes to the user-defined type, things may be different, especially when the struct is a combination of multiple types of variables. the momery format and size, in other words, the bit pattern will be different in C++ and C#.

This is just my 2 cents here. what I am saying may be wrong. I only want to bring up some thoughts.

Ok, program time.... try this:

First, declare your dll function as:
     [DllImport("TOCRdll.dll")]
     public static extern int TOCRGetJobResults(int JobNo, ref int ResultsInf, ref TOCRResults Results);

Then, call it:
     status = API.TOCRGetJobResults(JobNo, ref ResultsInf, ref TOCRResults);

Notes: there shouldn't be any necessary to have key word "ref" before the variable ResultsInf, but I just leave it.
0
 
LVL 2

Author Comment

by:derekthornton
ID: 9774803
I've tried that already,actually. It doesn't change much. It's really a pickle. It may make more sense if you saw the whole thing ..but it requires the .dll library, which I can't get the code to to paste. Can I email it to you?
0
 
LVL 2

Author Comment

by:derekthornton
ID: 9774889
Here. I've put the .zip file for it on this small site of mine for now.

http://www.members.cox.net/derek.thornton/OCRProject.zip

and you'll need the TOCR viewer if you decide to DL this and look at it.

http://www.transym.com/tocr13.zip

I appreciate the help you've already given, as well as the others who have contributed. I'm determined to make this project work one way or another.
0
 
LVL 2

Author Comment

by:derekthornton
ID: 9774895
0
 
LVL 1

Expert Comment

by:stone123
ID: 9780858
sorry, I haven't got any idea yet. Hope others could help you out.

good luck
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question