In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "C++ learning Bayesian classifier to achieve handwritten digit recognition". In daily operation, I believe many people have doubts about how C++ learns Bayesian classifier to achieve handwritten digit recognition. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt that "C++ learns Bayesian classifier to achieve handwritten digit recognition". Next, please follow the editor to study!
Let's take a brief look at this:
First of all, Bayesian formula is
Let's not talk about the specific explanation, let's talk about where Bayes is used in digital recognition. Except for the recognition part, the others, including traversing folders and digitizing pictures, remain the same; there are ten numbers from 0 to 9, so the denominator has ten terms, P (Bj) (j is the subscript) corresponds to 0 to 9, then the probability of each one is 1max 10, and the P (Bi) on the numerator is one of 0 to 9, so the probability is also 1 Bi 10.
(if you don't understand, it is recommended to take a look at Bayes.) so we can propose the denominator and assign a score, and then the formula Pi/ (P1+P2+P3+P4+P5+P6+P7+P8+P9) (Pi is P (A | Bi), and the rest is the value of I respectively). When this happens, I take a certain number of Hashi 9 is the probability that the test sample is this number, for example: iTunes 0, the probability that the test case is 0 is P1 / (P1+P2+P3+P4+P5+P6+P7+P8+P9+P10) (1 is the corresponding number 0).
So how do we find Pin? we count the probability that each bit of a sample is 1, which may not be clear, that is, if the digitized string of a picture of 0 is 00000000001000001100010010001010000111000000000 (49 bits), we count the number of bits 1 for each bit (as shown in the following figure, that is, the number of bits 1 in each sample longitudinally), and finally divide by the total number. My training library has 100 samples of a number. If we count 46 samples with the first digit 1 of the number 0, then the probability that the first digit of the number 0 is 1 is 0.46, and the other digits are counted in turn. Other figures are the same as above.
Finally, we can count the probability that each digit of each number is 1 to form a two-dimensional array of 10 to 49, that is, 10 digits, 49 digits each. Then we take a test case and calculate the probability with 10 numbers in turn, and the final probability is relatively large, so how do we calculate the probability that the test case is a certain number? Let's simply look at 49 bits as 3 digits. If the probability of the first, second, and third digits of 0 being 1 is 0.56, 0.05, 0.41, and the data string of the test case is 101, then the probability of 1 is multiplied directly, and the probability of 0 is subtracted by 1, and then multiplied again, that is, 0.56-0.95-0.41. This is almost all of our ideas.
For other ideas, see the last article, linking C++ programming templates to match ultra-detailed examples of recognizing handwritten numbers.
The following is my code, first of all, opencv has to be installed by myself, here I give a link, you can refer to the steps above.
How to install OpenCV Library in Python under Window system
In addition, my Bayes function is too long and should be divided into several functions. It will be easier to debug and read.
Detailed code explanations are in the comments, take a closer look at the understanding is good, if there are better methods and ideas, welcome to communicate and learn!
# include#include#include#include#include#include / / api and structure # include#include#include / / string to int data type contains using namespace std;using namespace cv; void ergodicTest (string filename, string name); / / traversal function string Image_Compression (string imgpath); / / compress the image and return the string void Bayes () / / Bayesian classifier int turn (char a); void main () {const char* filepath = "E:\\ learn\\ vsfile\\ c++project\\ pictureData\\ train-images"; ergodicTest (filepath, "train_num.txt") / / processing the training set const char* test_path = "E:\ learn\\ vsfile\\ c++project\\ pictureData\\ test-images"; ergodicTest (test_path, "test_num.txt"); Bayes ();} void ergodicTest (string filename, string name) / / traversing and saving the path to files {string firstfilename = filename + "\\ * .bmp"; struct _ finddata_t fileinfo Intptr_t handle; / / cannot use long because precision problems can lead to access conflicts. Longlong can also string rout = "E:\\ learn\\ vsfile\\ c++project\\ pictureData\\" + name; ofstream file; file.open (rout, ios::out); handle = _ findfirst (firstfilename.c_str (), & fileinfo) If (_ findfirst (firstfilename.c_str (), & fileinfo)! =-1) {do {file
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: 300
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.