forked from PillarsZhang/captcha-cv-ocr
-
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.
- Loading branch information
Showing
20 changed files
with
128 additions
and
64 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
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,24 @@ | ||
/* | ||
* @Author: renxia | ||
* @Date: 2023-12-28 18:53:57 | ||
* @LastEditors: renxia | ||
* @LastEditTime: 2023-12-28 19:43:22 | ||
* @Description: | ||
*/ | ||
/** | ||
* 滑块类型验证码匹配 | ||
*/ | ||
|
||
class SlideMatch { | ||
init() {} | ||
recognize(sliderImage, originalImage) { | ||
const cv = require('@u4/opencv4nodejs'); | ||
const sliderMat = cv.imdecode(Buffer.from(sliderImage, 'base64')); | ||
const originalMat = cv.imdecode(Buffer.from(originalImage, 'base64')); | ||
const matched = sliderMat.matchTemplate(originalMat, cv.TM_CCOEFF_NORMED); | ||
const matchedPoints = matched.minMaxLoc(); | ||
return matchedPoints; // .maxLoc.x; | ||
} | ||
} | ||
|
||
module.exports = new SlideMatch(); |
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
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,3 +1,3 @@ | ||
module.exports = { | ||
codeTypeList: ['simplest', 'dots_and_chars', 'grids_and_equations'], | ||
codeTypeList: ['slide_match', 'simplest', 'dots_and_chars', 'grids_and_equations'], | ||
}; |
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,8 +1,17 @@ | ||
const { NLogger } = require('@lzwme/fe-utils'); | ||
const { NLogger, color } = require('@lzwme/fe-utils'); | ||
const { readdirSync } = require('node:fs'); | ||
const { resolve } = require('node:path'); | ||
|
||
const logger = new NLogger('[CCOCR]'); | ||
const logger = new NLogger('[CCOCR]', { color }); | ||
exports.logger = logger; | ||
|
||
exports.log = function log(...msg) { | ||
logger.debug(...msg); | ||
} | ||
|
||
let codesList = []; | ||
function getCodesList() { | ||
if (codesList.length === 0) codesList = readdirSync(resolve(__dirname, '../codes')); | ||
return codesList; | ||
} | ||
exports.getCodesList = getCodesList; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 +1,19 @@ | ||
const path = require("path"); | ||
const cco = require("../index.js"); | ||
const path = require('path'); | ||
const { getCodesList, Cvocr, logger } = require('../index.js'); | ||
|
||
(async () => { | ||
for (const mode of cco.config.codeTypeList) { | ||
let cvocr = new cco.Cvocr(mode); // mode 表示验证码的种类 | ||
await cvocr.init(1); //其中的1表示需要启动的 OCR Worker 数(多线程) | ||
let ans = await cvocr.recognize(path.join(__dirname, "example", mode + ".jpg")); //支持文件地址、Base64、Buffer形式 | ||
console.log(`[${mode}]ans:`, ans); | ||
} | ||
process.exit(0); | ||
})() | ||
const codesList = getCodesList(); | ||
logger.info('codes:', codesList); | ||
|
||
for (const mode of codesList) { | ||
logger.info('test for:', mode); | ||
const cvocr = new Cvocr(mode); // mode 表示验证码的种类 | ||
await cvocr.init(1); //其中的1表示需要启动的 OCR Worker 数(多线程) | ||
const isSlideMatch = mode === 'slide_match'; | ||
const img = path.join(__dirname, `example/${mode}${isSlideMatch ? '-slider.png' : (mode === 'dots_and_chars' ? '.gif' : '.jpg')}`); | ||
const img2 = isSlideMatch ? path.join(__dirname, `example/${mode}-original.png`) : undefined; | ||
const ans = await cvocr.recognize(img, img2); //支持文件地址、Base64、Buffer形式 | ||
logger.log(`[${mode}]ans:`, ans); | ||
} | ||
process.exit(0); | ||
})(); |
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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