Skip to content

Commit

Permalink
Fixed bug in not binarizing the input data
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor-sketch committed Jun 28, 2024
1 parent 5e74967 commit 007371e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
</footer>
<script src="./js/tutorial.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@4/dist/tesseract.min.js"></script>
<script src="./js/parser.js"></script>
<script>
const fileInput = document.getElementById('fileInput');

Expand Down Expand Up @@ -207,8 +206,11 @@
const script = document.createElement('script');
script.src = './src/sudoku_solver.js';
document.body.appendChild(script);


function solveSudoku() {
const boardStr = readBoard();
console.log(boardStr);
if (boardStr.length !== 81) {
alert('Please fill all cells with valid numbers');
return;
Expand All @@ -221,6 +223,7 @@
const csp = new Module.SudokuCSP(boardStr);
csp.solve();
const solvedBoardStr = csp.getBoard();
console.log(solvedBoardStr);
updateBoard(solvedBoardStr);

celebrate();
Expand Down Expand Up @@ -287,6 +290,8 @@
}

</script>
<script src="./js/parser.js"></script>

</body>

</html>
5 changes: 5 additions & 0 deletions docs/js/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ function processImage(src) {
reject(new Error("No image source provided."));
return;
}
// make black and white and extream contrast (black and white)


const img = new Image();
img.onload = function () {
Expand All @@ -181,7 +183,10 @@ function processImage(src) {
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);

// Binarize and enhance the image

let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
imageData = binarizeImage(imageData);

ctx.putImageData(imageData, 0, 0);

const processedImageSrc = canvas.toDataURL();
Expand Down

0 comments on commit 007371e

Please sign in to comment.