-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got tesseract number recognition working and made work with sudoku so…
…lver
- Loading branch information
1 parent
cd8a835
commit 417a5d6
Showing
16 changed files
with
289 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
#include <solver/solver.h> | ||
#include <solver/textRecognition.h> | ||
#include <solver/board_detection.h> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
|
||
int main(int argc, char** argv) { | ||
|
||
#if 0 | ||
// Open the camera. | ||
cv::VideoCapture capture(0); | ||
if (!capture.isOpened()) { | ||
std::cout << "Error opening video stream or file" << std::endl; | ||
return -1; | ||
} | ||
|
||
cv::Mat frame, output_frame; | ||
|
||
cv::Mat frame, preview_frame; | ||
while (1) { | ||
// Capture the frame. | ||
/* | ||
capture >> frame; | ||
if (frame.empty()) { | ||
std::cout << "No captured frame" << std::endl; | ||
break; | ||
} | ||
|
||
output_frame = puzzle_solver(frame); | ||
preview_frame = prepare_frame(frame); | ||
std::array<cv::Point2f, 4> corners = find_corners(preview_frame); | ||
cv::line(frame, corners[0], corners[1], cv::Scalar(0, 255, 0), 4); | ||
cv::line(frame, corners[1], corners[2], cv::Scalar(0, 255, 0), 4); | ||
cv::line(frame, corners[2], corners[3], cv::Scalar(0, 255, 0), 4); | ||
cv::line(frame, corners[3], corners[0], cv::Scalar(0, 255, 0), 4); | ||
|
||
// Present the frame. | ||
cv::imshow("Frame", output_frame); | ||
*/ | ||
// Quit if ESC pressed. | ||
cv::imshow("Frame", frame); | ||
|
||
// Quit if ESC pressed. | ||
char c = (char)cv::waitKey(25); | ||
if (c == 27) break; | ||
} | ||
#else | ||
|
||
/* cv::imwrite("output.png", frame); */ | ||
cv::Mat frame = cv::imread("output.png"); | ||
#endif | ||
|
||
|
||
// Now do processing on the frame! | ||
std::optional<SudokuGrid> grid = puzzle_solver(frame); | ||
(void)grid; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include <opencv2/opencv.hpp> | ||
#include <solver/sudoku_grid.h> | ||
|
||
cv::Mat puzzle_solver(cv::Mat& frame); | ||
std::optional<SudokuGrid> puzzle_solver(cv::Mat& frame); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
|
||
using SudokuGrid = std::array<std::array<int, 9>, 9>; | ||
|
||
void print_grid(const SudokuGrid& grid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <solver/sudoku_grid.h> | ||
#include <optional> | ||
|
||
class Cell { | ||
public: | ||
int row; | ||
int col; | ||
std::vector<int> possibleNums; | ||
}; | ||
|
||
class SudokuSolver { | ||
SudokuGrid grid; | ||
std::vector<Cell> list; | ||
|
||
public: | ||
void setGrid(SudokuGrid g); | ||
bool solve(); | ||
bool isSafe(int row, int col, int num); | ||
void setInitialPossibleNums(); | ||
std::optional<SudokuGrid> doEverything(SudokuGrid initialGrid); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
#include <array> | ||
|
||
std::array<std::array<int, 9>, 9> recognize_board_numbers(std::array<cv::Mat, 81>& frame); | ||
|
||
/* std::string recognize_text(cv::Mat& frame); */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
#include <solver/solver.h> | ||
#include <solver/board_detection.h> | ||
#include <solver/text_recognition.h> | ||
#include <solver/sudoku_solver.h> | ||
|
||
cv::Mat puzzle_solver(cv::Mat& frame) { | ||
std::optional<SudokuGrid> puzzle_solver(cv::Mat& frame) { | ||
// Solve stuff here! | ||
return frame; | ||
std::array<cv::Mat, 81> cells = detect_board(frame); | ||
|
||
SudokuGrid grid = recognize_board_numbers(cells); | ||
|
||
std::cout << "Original puzzle:" << std::endl; | ||
print_grid(grid); | ||
|
||
SudokuSolver solver; | ||
std::optional<SudokuGrid> solved_grid = solver.doEverything(grid); | ||
|
||
if (solved_grid) { | ||
std::cout << "Solved puzzle:" << std::endl; | ||
print_grid(*solved_grid); | ||
} | ||
else { | ||
std::cout << "Could not solve puzzle!!" << std::endl; | ||
} | ||
|
||
return solved_grid; | ||
} |
Oops, something went wrong.