我的应用程序试图识别抽奖日期,并在彩票上播放号码。但是,由于票证背景上的图像,我无法检测日期和号码。如何修改我的代码以实现我的目标?
最初,我试图找到一个API,该API将接受彩票的条形码,如果彩票是中奖票,则返回。在对网络进行了广泛的研究之后,我意识到这样的方法是不可能的,所以现在我尝试使用字符识别方法来检测数字和绘制日期。与此信息,我将交叉参照它与获奖的数字和抽签日期。这里的好处是,想要的字符都是黑色的,其他的都有不同的颜色。我试图使用this逻辑,但我很难操纵代码来实现我的目的。

所需的代码将输出“第一张抽签:”日期和播放的6个数字(在A06:的右边)。
我真正得到的是:
“no”lo0“Wm”{3153:-.:,.4,LDTTU PLUS,;7N9"??ms: 10 20 24 25 32 3.7总计:R5‘00.7’hc?‘e: IWHW 753:“15/0/19 FE:4;1-071094555258an94
//function I use to run OCR
function runOCR(url) {
Tesseract.recognize(url)
.then(function(result) {
console.log(result.text);
}).progress(function(result) {
console.log('Status: ' + result['status']);
});
}
提前感谢您的有效解决方案。我只是需要有人帮助我在像素出红和白的背景,以便前景变得容易识别。我对这里的两行感兴趣:抽签日期,上面写着第一次抽签: Saterday 20/07/19和A06: 10 20 24 25 32 37
发布于 2019-07-20 08:17:03
哇哦..。我试过了。
我首先将图像转换为灰度图像,然后检查该值是否高于或低于阈值。只需上传图像并移动滑块以更改阈值即可。
(您可能需要在整页lol中打开它)
有一个好的:)
const fileReader = document.getElementById('fileReader');
const sliderThreshold = document.getElementById('sliderThreshold');
const inputCanvas = document.getElementById('inputCanvas');
const outputCanvas = document.getElementById('outputCanvas');
const inputCtx = inputCanvas.getContext('2d');
const outputCtx = outputCanvas.getContext('2d');
sliderThreshold.addEventListener('input', e => displayResult(e.target.value));
fileReader.addEventListener('change', inputEvent => {
let reader = new FileReader();
reader.addEventListener('load', readerEvent => {
let img = new Image();
img.addEventListener('load', () => {
inputCanvas.width = img.width;
inputCanvas.height = img.height;
inputCtx.drawImage(img, 0, 0);
displayResult(50);
});
img.src = readerEvent.target.result;
});
reader.readAsDataURL(inputEvent.target.files[0]);
});
function displayResult(threshold) {
let imageData = inputCtx.getImageData(0,0, inputCanvas.width, inputCanvas.height);
let data = imageData.data;
for(let i = 0; i < data.length; i += 4) {
// Convert RGB values to grayscale (you can look that up)
let grayscale = data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11;
// Check if the value is obove or below the threshold value and return white or black
let finalColor = grayscale < threshold ? 0 : 255;
// Asign the color
data[i] = finalColor;
data[i + 1] = finalColor;
data[i + 2] = finalColor;
}
// Put the data into another canvas so we
outputCanvas.width = imageData.width;
outputCanvas.height = imageData.height;
outputCtx.putImageData(imageData, 0, 0);
}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.canvasContainer {
overflow-y: scroll;
display: inline-block;
}
</style>
</head>
<body>
<input type="file" id="fileReader">
Threshold<input type="range" min="0" max="255" id="sliderThreshold">
<div class="canvasContainer">
<canvas id="outputCanvas"></canvas>
</div>
<div class="canvasContainer">
<canvas id="inputCanvas"></canvas>
</div>
<script src="./index.js"></script>
</body>
</html>
https://stackoverflow.com/questions/57099268
复制相似问题