基本信息
源码名称:EMGUCV OCR识别
源码大小:0.01M
文件格式:.zip
开发语言:C#
更新时间:2017-11-27
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 10 元 
   源码介绍

VS C# OCR识别车牌实例

//----------------------------------------------------------------------------
//  Copyright (C) 2004-2017 by EMGU Corporation. All rights reserved.       
//----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Diagnostics;

namespace Emgu.CV.OCR
{
    /// <summary>
    /// Library to invoke Tesseract OCR functions
    /// </summary>
    public static partial class OcrInvoke
    {
        static OcrInvoke()
        {
            //dummy code that is used to involve the static constructor of CvInvoke, if it has not already been called.
            CvInvoke.CheckLibraryLoaded();
        }

        #region Tesseract
        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern IntPtr TessBaseAPICreate();

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern int TessBaseAPIInit(
            IntPtr ocr,
            IntPtr dataPath,
            IntPtr language,
            OcrEngineMode mode);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIRelease(ref IntPtr ocr);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPISetImage(IntPtr ocr, IntPtr image);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPISetImagePix(IntPtr ocr, IntPtr pix);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetUTF8Text(
           IntPtr ocr,
           IntPtr text);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetHOCRText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetTSVText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetBoxText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetUNLVText(IntPtr ocr, IntPtr vectorOfByte);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIGetOsdText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPIExtractResult(IntPtr ocr, IntPtr charSeq, IntPtr resultSeq);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        [return: MarshalAs(CvInvoke.BoolMarshalType)]
        internal static extern bool TessBaseAPIProcessPage(
            IntPtr ocr,
            IntPtr pix,
            int pageIndex,
            IntPtr filename,
            IntPtr retryConfig,
            int timeoutMillisec,
            IntPtr renderer);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        [return: MarshalAs(CvInvoke.BoolMarshalType)]
        internal static extern bool TessBaseAPISetVariable(
            IntPtr ocr,
            [MarshalAs(CvInvoke.StringMarshalType)]
            String varName,
            [MarshalAs(CvInvoke.StringMarshalType)]
            String value);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern IntPtr TesseractGetVersion();

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessBaseAPISetPageSegMode(IntPtr ocr, PageSegMode mode);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern PageSegMode TessBaseAPIGetPageSegMode(IntPtr ocr);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern int TessBaseAPIGetOpenCLDevice(IntPtr ocr, ref IntPtr device);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern IntPtr TessBaseAPIAnalyseLayout(
            IntPtr ocr,
            [MarshalAs(CvInvoke.BoolMarshalType)]
            bool mergeSimilarWords);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern int TessBaseAPIIsValidWord(
            IntPtr ocr,
            [MarshalAs(CvInvoke.StringMarshalType)]
            String word);
        #endregion

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessPageIteratorRelease(ref IntPtr iterator);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern void TessPageIteratorGetOrientation(IntPtr iterator, ref PageOrientation orientation, ref WritingDirection writingDirection, ref TextlineOrder order, ref float deskewAngle);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        [return: MarshalAs(CvInvoke.BoolMarshalType)]
        internal static extern bool TessPageIteratorGetBaseLine(
           IntPtr iterator,
           PageIteratorLevel level,
           ref int x1, ref int y1, ref int x2, ref int y2);

        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern OcrEngineMode TessBaseAPIGetOem(IntPtr ocr);


        [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
        internal static extern int TessBaseAPIRecognize(IntPtr ocr);
    }
}