Opencv C++ Recognize number - c++

this should be easy. I'm working on a Sedoku solver and I and trying to figure out how to tell which number I am looking at.
I am able to isolate the number as seen above. I just can't get any image recognition to work. I've tried Knearest and something called tesseract but to no avail. Any help?

for easy tasks like this, I would not recommend using something like tesseract. Just think about some simple trick way. For example, threshold it and count the black pixels and see what are the count for each number. of course this method will fail for 6 and 9 so you may cut the number into two half and count each one and compare.. and so on.

Related

How to solve a game with repeating positions (Teeko)

I have been trying to find a algorithm to strongly solve the game Teeko. The game is played on a 5x5 board were each player has 4 pieces and attempts align them in any direction or create a square out of them. (assume there is no drop phase)
I have tried solving the game by using a negamax with alpha beta pruning and other optimizations like a transposition table but that has not seemed to have worked because the solver would usually get stuck in loops were neither player wants to deviate from there strategy as it would result in them loosing. From my research I have found stuff like Nash Equilibrium as a potential solution but I cant figure out how to implement it. Furthermore, I have found that the game has been solved and found that the with prefect play it result in a draw previously: https://pcarrier.com/teeko/text/teeko.results.txt
Are there any algorithms that might be able to give the same result as minimax and hanlde repeating positions and how could I implement it and are there any other algorithms that give the same result as minimax?
Minimax (or Negamax) is well capable of handling repeating positions using transposition tables, as you mention in your question. Transposition tables are complicated to implement though so maybe you have a bug?
The problem with minimax is that you either:
NEed to solve it until the game is completed to get a score. This is possible for simple games like tic-tac-toe, but not for more complicated games like chess.
Score each node using some heuristic function, which is the case for e.g. chess.
I am not sure about Teeko, is it possible to get to all leaf nodes with minimax and alpha beta pruning? Could you do other things to reduce the search tree, like transpotision tables or other cut offs? If so then minimax is a great option.
Is it possible to create some kind of evaluation function for this game? It seems hard to me, but maybe that is because I know too little about the game. Is it better to have central squares? Better to get 2 in a row than to spread out pieces? Evaluation function is something you could have a look at if you are a good player of the game, or find good sources online.

Computer vision algorithm to use for making lines thinner

I have lecture notes written by a professor using a stylus.
A sample:
The width of the line used here is making reading difficult for me. I would like to make the lines thinner. The only solution I could think of is dilating the image. This gives a passable result:
The picture above is with uniform kernel of shape (2, 2) applied once; I've tried a bunch of kernel types, widths & numbers of iterations to arrive at this version that looks best to me.
However, I can't help but wonder if there's maybe another applicable algorithm that I'm missing; one that could lead to even better results? I wasn't able to google any computer vision approaches to font thinning, so I would appreciate any information on the subject.
Have been monitored such info during several days. Try to use Thinning described here, the link is also in the references to OpenCV-Python-Tutorial on morphological transforms. Taking Image Gradient can help, but it will make the image Grayscale, and with inverting colors you can get black-on-white text. Try to leave original color on black pixels location when original and final images are stacked.

How to compute difference of two images

I'm taking a course in image recognition. We've just been taught about corner detection, e.g Harris.
I'm wondering what would be the next step in computation after it?
Let's take for example an image from wiki - https://en.wikipedia.org/wiki/Corner_detection#/media/File:Corner.png
Lowercase n, denoting a power on t, resulted in tree points being detected.
If I were to use this data, what do I do with it to know it might be a 'n' letter? Is there a way to compute similarity of this line that n got transformed into against an alphabet of choice and pick a best match?
What if I'm not looking for something as simple as a black letter on white background?
Well, Just for the records, I will state the Machine Learning method, here's a good paper for that matter : http://www.cs.stanford.edu/~acoates/papers/coatesetal_icdar_2011.pdf
Also, OpenCV has it's own implementation of it and it might work for your case, as long as it's somehow simple to do. More than that, you'll need a more sophisticated one or create your own (I don't recommend that !).

Estimate color distribution with Gaussian mixture model

I am trying to use two Gaussian mixtures with EM algorithm to estimate color distribution of a video frame. For that, I want to use two separate peaks in the color distribution as the two Gaussian means to facilitate the EM calculation. I have several difficulties with the implementation of these in OpenCV.
My first question is: how can I determine the two peaks? I've searched about peak estimation in OpenCV, but still couldn't find any seperate function. So I am going to determine two regions, then find their maximum values as peaks. Is this way correct?
My second question is: how to perform Gaussian mixture model with EM in OpenCV? As far as I know, the "cv::EM::predict" function could give me the index of the most probable mixture component. But I have difficulties with training EM. I've searched and found some other codes, but finding the correct parameters is too much difficult for. Could someone provide me any example code for this? Thank you in advance.
#ederman, try {OpenCV library location}\opencv\samples\cpp\em.cpp instead of the web link. I think the sample code in the link is out of date now. I have successfully compiled the sample code in OpenCV 2.3.1. It shouldn't be a problem for 2.4.2.
Good luck:)
My first question is: how can I determine the two peaks?
I would iterate through the range of sample values possible, and test when the does EM.predict(sample)[0] peaks.

streaking image with opencv

So I've been working on some code for a couple weeks and it is far from complete, However the one thing keeping me from moving forward is a strange problem which I cannot figure out. I've been stuck for a few days now
The code below is for a program which accepts to command line arguments, an infile and an outfile. The infile will be a small square binary tif image, somewhere between 200x200 and 400x400. At this point the program should tile the image, stretching each part to various lengths. The outfile should have a height of 768 pixels and a width in the ballpark of 50k to 60k pixels. I apologize, but I can't supply them for example, they are confidential.
While it does work, sort of, it only replicates images to around 34k pixels and stops. The last row continues to display a black streak to the end.
I think the problem is coming from my create1track() function. I have tried optimizing it with very few changes. If I use a while loop as opposed to a for loop I get three black streaks as opposed to one. Does anyone have any suggestions on why it might do this?
It's a pretty simple function. I don't see why it shouldn't work
I'm posting my entire code, hoping for some advice. A copy is stored is stored here:
https://www.dropbox.com/s/sp153rz252uikue/main_backup.cpp
I'd accept any other criticism/input, just be nice, I just started teaching myself c++ about 2 months ago and since I'm pretty new to programming in general, I'm sure there is plenty of things I'm doing wrong.