[Programmer's method of eating chicken] uses OCR text recognition + Baidu algorithm search to play the game of winning prize in the Q & A contest, millions of heroes, and cheese Superman, and ocr cheese.

Source: Internet
Author: User

[Programmer's method of eating chicken] uses OCR text recognition + Baidu algorithm search to play the game of winning prize in the Q & A contest, millions of heroes, and cheese Superman, and ocr cheese.

[Upload first ]:

 

I. Principle:

In fact, the principle is very simple:

1. screen your mobile phone to your computer;

2. Capture the question part of the screen cast to identify and obtain the question and three answers;

3. Search the answers based on certain algorithms to obtain the recommended answers;

4. Added some other auxiliary functions, such as browser search result display, keyword highlighting, and clickable browser;

 

Ii. battalion commander, present the code of my Italian ............ to Youjun.

1. Mobile phone screen Casting:

There are many methods. Here we only list a few of them that are commonly used and easy to use:

A. IOS: in the LAN, you can use the apple screen recorder (airplay) in iTools to screen cast;

B. Android: using the connection line, you can use Totall Control to cast the picture of the Android mobile phone to a computer. In addition, you can directly operate the mobile phone on the computer;

C. simulators: Generally, they are Android simulators. You can download and install them on your own;

 

2. Capture questions and answers on the screen

A. Set the region first.

I created a form specifically used to set the region and named it frmCutter.

Principle: When frmCutter is opened in the main form, the frmCutter is displayed in full. At the same time, capture an image of the entire screen and set it to a background image in the frmCutter form.

In this way, you can set it freely on frmCutter.

When the main form opens the frmCutter form:

1 // create an image of the same size as the Screen. 2 Bitmap catchBmp = new Bitmap (Screen. allScreens [0]. bounds. width, Screen. allScreens [0]. bounds. height); 3 4 // create a canvas, let's draw a picture on the canvas 5 // This canvas is the same size as the screen 6 // we can draw a picture on this blank image through the Graphics class 7 Graphics g = Graphics. fromImage (catchBmp); 8 9 // copy the screen image to 10 Gb of the blank image catchBmp we created. copyFromScreen (new Point (0, 0), new Point (0, 0), new Size (Screen. allScreens [0]. bounds. width, Screen. allScreens [0]. bounds. height); 11 12 // create the Form 13 frmCutter _ frmCutter = new frmCutter (); 14 _ frmCutter. tag = this; 15 16 // indicates that the background image of the form is a screen image 17 _ frmCutter. backgroundImage = catchBmp; 18 19 _ frmCutter. width = Screen. allScreens [0]. bounds. width; 20 _ frmCutter. height = Screen. allScreens [0]. bounds. height; 21 DialogResult dr = _ frmCutter. showDialog ();

Then, write several events in the frmCutter form:

1 // when right-clicking, deselect 2 private void frmCutter_MouseClick (object sender, MouseEventArgs e) 3 {4 if (e. button = MouseButtons. right) 5 {6 this. dialogResult = DialogResult. OK; 7 this. close (); 8} 9} 10 11 // when you click the left mouse button, start to draw area Fig 12 private void frmCutter_MouseDown (object sender, MouseEventArgs e) 13 {14 // click the left mouse button to start drawing, that is, 15 if (e. button = MouseButtons. left) 16 {17 // if the capture does not start 18 if (! _ CatchStart &&! _ CatchFinished) 19 {20 _ catchStart = true; 21 22 // Save the cursor and press the coordinate 23 Point newPoint = new Point (e. x, e. y); 24 25_downpoint = newPoint; 26 27 Tools. startPoint = newPoint; 28} 29} 30} 31 32 // draw a rectangle 33 private void frmCutter_MouseMove (object sender, mouseEventArgs e) 34 {35 # region make sure to start 36 if (_ catchStart &&! _ CatchFinished) 37 {38 // create an image object to make it the same as the screen image 39 Bitmap copyBmp = (Bitmap) Tools. screenShots. clone (); 40 41 // obtain the coordinate 42 Point newPoint = new Point (_ downPoint. x, _ downPoint. y); 43 44 // create a canvas and paint brush 45 Graphics g = Graphics. fromImage (copyBmp); 46 Pen p = new Pen (Color. red, 1); 47 48 // obtain the length and width of the rectangle 49 int width = Math. abs (e. x-_ downPoint. x); 50 int height = Math. abs (e. y-_ downPoint. y); 51 if (e. X <_ down Point. x) 52 {53 newPoint. X = e. x; 54} 55 if (e. Y <_ downPoint. y) 56 {57 newPoint. Y = e. y; 58} 59 60 _ catchRectangle = new Rectangle (newPoint, new Size (width, height); 61 62 Tools. catchRectangle = new Rectangle (newPoint, new Size (width, height); 63 Tools. catchRectangleSize = new Size (width, height); 64 65 66 // draw a rectangle on the canvas for 67 GB. drawRectangle (p, _ catchRectangle); 68 69 // release the current drawing board for 70 GB. dispose (); 71 p. dispose (); 72 // create a new drawing board 73 Graphics g1 = this from the current form. createGraphics (); 74 75 // draw the image you just painted on the Form 76 // Why not draw it directly on the current form? 77 // if you do this by yourself, drawing a rectangle on the form will cause image jitter and there are no number of rectangles 78 // This implementation also belongs to the secondary buffer technology 79 g1.DrawImage (copyBmp, new Point (0, 0); 80 g1.Dispose (); 81 // release the copy image to prevent memory consumption of 82 copyBmp. dispose (); 83} 84 # endregion 85} 86 87 // when you click the mouse, the rectangle is drawn 88 private void frmCutter_MouseUp (object sender, MouseEventArgs e) 89 {90 if (e. button = MouseButtons. left) 91 {92 // if it has already started, the Left mouse button pops up to set 93 if (_ catchStart) 94 {95 Tools. endPoint = new Point (e. x, e. y); 96 97 _ catchStart = false; 98 _ catchFinished = true; 99} 100} 101 102 103 // double-click, set 104 private void frmCutter_MouseDoubleClick (object sender, MouseEventArgs e) 105 {106 if (e. button = MouseButtons. left & _ catchFinished) 107 {108 if (this. tag! = Null) 109 {110 frmMain _ frmMain = (frmMain) this. Tag; 111 if (_ frmMain! = Null) 112 {113 // _ frmMain. btnRead. focus (); 114 _ frmMain. readImageResult (); 115} 116} 117 118 this. dialogResult = DialogResult. OK; 119 this. close (); 120} 121}

 

B. After the region is set, each time a question appears, it changes to the region:

1 // capture the set area Screen Image 2 Bitmap _ screenShots = new Bitmap (Screen. allScreens [0]. bounds. width, Screen. allScreens [0]. bounds. height); 3 // create a canvas, let's draw a picture on the canvas 4 // This canvas is the same size as the screen 5 // we can draw 6 Graphics g_screenShots = Graphics on this blank image through the Graphics class. fromImage (_ screenShots); 7 // copy the screen image to 8 g_screenShots.CopyFromScreen (new Point (0, 0), new Point (0, 0 ), new Size (Screen. allScreens [0]. bounds. width,
Screen. allScreens [0]. bounds. height); 9 10 // cut the image 11_catchbmp = new Bitmap (Tools. catchRectangleSize. width, Tools. catchRectangleSize. height); 12 Graphics g = Graphics. fromImage (_ catchBmp); 13g. drawImage (_ screenShots, new Rectangle (0, 0, Tools. catchRectangleSize. width, Tools. catchRectangleSize. height ),
Tools. CatchRectangle, GraphicsUnit. Pixel); 14g. Dispose (); 15 g_screenShots.Dispose (); 16 17 // display Image 18 this. imgCut. BackgroundImage = (Image) _ catchBmp;

 

C. Use OCR to identify the captured Questions and answers

For example, I have set and captured this image:

OCR software and APIs are also used to recognize text in images. Previously, I used Google tesseract4.0, which was installed on the local machine without a dictionary. The recognition rate is average.

Later, I found that Baidu OCR calls 500 times a day for free, making a decisive transfer! Facts have proved that the accuracy rate is much higher.

 

D. Obtain the recognition result and perform Baidu search after processing the recognition result:

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

1 /// <summary> 2 // Question class 3 /// </summary> 4 public class QuestionModel 5 {6 /// <summary> 7 // Question 8 /// </summary> 9 public string Question {get; set;} 10 11 /// <summary> 12 // Answer 113 /// </summary> 14 public string Answer1 {get; set ;} 15 16 /// <summary> 17 /// answer 218 /// </summary> 19 public string Answer2 {get; set ;} 20 21 /// <summary> 22 // Answer 323 /// </summary> 24 public string Answer3 {get; set;} 25}

 

E. Search Baidu and show the following answers:

A). algorithm search:

1. Search Baidu by question. The number of times the answer appears in the search result.

2. Search by question + answer. Obtain the number of Baidu results for each combination.

Then, based on the weights of the two methods, the user can decide which result is preferred.

B). Secondary search:

There is also a browser on the right to display the search results for Baidu Based on the question as soon as the recognition results are obtained, and three answer keywords are highlighted in it.

 

3. Sit down and eat chicken!

Automatic, automatic identification, automatic search, automatic reference answers, automatic display of search pages, and highlighted keywords ......

With a series of auxiliary functions, it is hard to know whether to eat chicken or not ~

 

(PS: we warmly welcome the majority of Taoist friends to discuss and give pointers. Let's take them to the next level !)

 

 

2018.01.25.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.