Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use OCR text to recognize all kinds of pictures and texts

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use OCR text to recognize all kinds of pictures and text". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use OCR text to recognize all kinds of pictures and text".

[previous effect picture]:

1. Principle:

In fact, the principle is simple:

1. The mobile phone is projected onto the computer.

two。 Capture the question part of the screen, identify it, and get the question and three answers.

3. Search the answer according to a certain algorithm and get the recommended answer.

4. Some other auxiliary functions have been added, such as browser search results display, keyword highlighting, browser clickability and so on.

Second, second battalion commander, put my Italy. The code, show it to the friendly forces.

1. Mobile phone screen:

There are many ways. Here are only a few that are more commonly used and feel easy to use:

A.IOS: in the local area network, you can use the airplay of Apple screencap in iTools to cast the screen.

b. Android: using the connection cable, you can use Totall Control to project the picture of the Android phone to the computer, and the computer can also operate the phone directly.

c. Simulators: generally Android simulators; can be downloaded and installed by yourself

two。 Intercept the questions and answers in the picture

a. First set the area to be screenshot.

I created a form specifically for setting the screenshot area and named it frmCutter.

Principle: when the main form opens frmCutter, the frmCutter will be fully displayed. At the same time, capture a picture of the entire screen and set it as the background picture of the frmCutter form.

So you can set it up freely on frmCutter.

When the main form opens the frmCutter form:

/ / create a picture with the same screen size

Bitmap catchBmp = new Bitmap (Screen.AllScreens [0] .bounds.width, Screen.AllScreens [0] .bounds.Height)

/ / create a drawing board so that we can draw on it.

/ / this artboard is a picture as big as the screen.

/ / We can use the class Graphics to draw a picture on this blank picture.

Graphics g = Graphics.FromImage (catchBmp)

/ / copy the screen image to the blank image catchBmp we created.

G.CopyFromScreen (new Point (0,0), new Point (0,0), new Size (Screen.AllScreens [0] .bounds.Width, Screen.AllScreens [0] .bounds.height))

/ / create a screenshot form

FrmCutter _ frmCutter = new frmCutter ()

_ frmCutter.Tag = this

/ / indicates that the background picture of the form is a screen picture.

_ frmCutter.BackgroundImage = catchBmp

_ frmCutter.Width = Screen.AllScreens [0] .bounds.width

_ frmCutter.Height = Screen.AllScreens [0] .bounds.Height

DialogResult dr = _ frmCutter.ShowDialog ()

Then in the frmCutter form, write several events:

/ / cancel the setting when you right-click

Private void frmCutter_MouseClick (object sender, MouseEventArgs e)

{

If (e.Button = = MouseButtons.Right)

{

This.DialogResult = DialogResult.OK

This.Close ()

}

}

/ / when you click the left mouse button, start drawing the area map.

Private void frmCutter_MouseDown (object sender, MouseEventArgs e)

{

/ / press the left mouse button to start drawing, that is, a screenshot

If (e.Button = = MouseButtons.Left)

{

/ / if the capture does not start

If (! _ catchStart & &! _ catchFinished)

{

_ catchStart = true

/ / Save the mouse down coordinates at this time

Point newPoint = newPoint (e.x, e.y)

_ downPoint = newPoint

Tools.StartPoint = newPoint

}

}

}

/ / when the mouse moves, the rectangle is drawn according to the moving mouse and the first point when clicked

Private void frmCutter_MouseMove (object sender, MouseEventArgs e)

{

# region make sure the screenshot starts

If (_ catchStart & &! _ catchFinished)

{

/ / create a new picture object to make it the same as the screen picture

Bitmap copyBmp = (Bitmap) Tools.ScreenShots.Clone ()

/ / obtain the coordinates pressed by the mouse

Point newPoint = newPoint (_ downPoint.X, _ downPoint.Y)

/ / create a new artboard and brush

Graphics g = Graphics.FromImage (copyBmp)

Pen p = new Pen (Color.Red, 1)

/ / get the length and width of the rectangle

Int width = Math.Abs (e.x-_ downPoint.X)

Int height = Math.Abs (e.y-_ downPoint.Y)

If (e.x)

< _downPoint.X) { newPoint.X = e.X; } if (e.Y < _downPoint.Y) { newPoint.Y = e.Y; } _catchRectangle = new Rectangle(newPoint, new Size(width, height)); Tools.CatchRectangle = new Rectangle(newPoint, new Size(width, height)); Tools.CatchRectangleSize = new Size(width, height); // 将矩形画在画板上 g.DrawRectangle(p, _catchRectangle); // 释放目前的画板 g.Dispose(); p.Dispose(); // 从当前窗体创建新的画板 Graphics g1 = this.CreateGraphics(); // 将刚才所画的图片画到截图窗体上 // 为什么不直接在当前窗体画图呢? // 如果自己解决将矩形画在窗体上,会造成图片抖动并且有无数个矩形 // 这样实现也属于二次缓冲技术 g1.DrawImage(copyBmp, new Point(0, 0)); g1.Dispose(); // 释放拷贝图片,防止内存被大量消耗 copyBmp.Dispose(); } #endregion } //鼠标点击后,弹起来时,完成矩形的绘制 private void frmCutter_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { // 如果截图已经开始,鼠标左键弹起设置截图完成 if (_catchStart) { Tools.EndPoint = new Point(e.X, e.Y); _catchStart = false; _catchFinished = true; } } } //双击,确定当前选择的设置 private void frmCutter_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && _catchFinished) { if (this.Tag != null) { frmMain _frmMain = (frmMain)this.Tag; if (_frmMain != null) { //_frmMain.btnRead.Focus(); _frmMain.ReadImageResult(); } } this.DialogResult = DialogResult.OK; this.Close(); } } B.设置好截图区域后,每次题目出现时,变对该区域截图: //截取设置的区域屏幕图片 Bitmap _screenShots = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height); // 创建一个画板,让我们可以在画板上画图 // 这个画板也就是和屏幕大小一样大的图片 // 我们可以通过Graphics这个类在这个空白图片上画图 Graphics g_screenShots = Graphics.FromImage(_screenShots); // 把屏幕图片拷贝到我们创建的空白图片 CatchBmp中 g_screenShots.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width,   Screen.AllScreens[0].Bounds.Height)); //剪切的图片 _catchBmp = new Bitmap(Tools.CatchRectangleSize.Width, Tools.CatchRectangleSize.Height); Graphics g = Graphics.FromImage(_catchBmp); g.DrawImage(_screenShots, new Rectangle(0, 0, Tools.CatchRectangleSize.Width, Tools.CatchRectangleSize.Height),   Tools.CatchRectangle, GraphicsUnit.Pixel); g.Dispose(); g_screenShots.Dispose(); //显示图像 this.imgCut.BackgroundImage = (Image)_catchBmp; C.将截到的问题和答案图片,用OCR识别 比如,我现在设置并截取到了这张图片:

There are also a lot of OCR software and API to recognize the text in the picture. I used to use Google tesseract4.0, installed on this machine, did not do a thesaurus, the recognition rate is general. Later found that Baidu OCR calls 500 times a day for free, decisive transition! Facts have proved that the correct rate is still much higher.

d. Get the recognition result, process the recognition result, and search for Baidu:

A question entity is created, which is convenient to use later:

/ / /

/ / examination questions category

/ / /

Public class QuestionModel

{

/ / /

/ / problem

/ / /

Public string Question {get; set;}

/ / /

/ / answer 1

/ / /

Public string Answer1 {get; set;}

/ / /

/ / answer 2

/ / /

Public string Answer2 {get; set;}

/ / /

/ / answer 3

/ / /

Public string Answer3 {get; set;}

}

e. Baidu searches and displays the reference answer:

a)。 Algorithm search:

1. Use the title to search for Baidu. The number of times the query answer appears in the search results.

two。 Search with questions + answers. Get the number of Baidu results for each combination.

Then, according to the weighting of the above two methods, the user can decide which result to prefer.

b)。 Secondary search:

There is also a browser on the right, which can show the results of searching Baidu according to the title as soon as you get the recognition result, and highlight three answer keywords in it.

Third, sit and wait for the chicken!

Automatic screenshot, automatic recognition, automatic search, automatically give reference answers, automatically show the search page and highlight keywords.

With a series of auxiliary functions, it is difficult not to eat chicken.

Thank you for your reading, the above is the content of "how to use OCR text to recognize all kinds of pictures and text". After the study of this article, I believe you have a deeper understanding of how to use OCR text to recognize all kinds of pictures and texts, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report