-
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
1 parent
8c90109
commit 4863354
Showing
10 changed files
with
173 additions
and
19 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
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,79 @@ | ||
import type { _IsTaskType } from "../_BaseTaskRequest"; | ||
import { BaseTask } from "../_BaseTaskRequest"; | ||
|
||
const _VisionEngineModules = [ | ||
"slider_1", | ||
"rotate_1", | ||
"space_detection" | ||
] as const; | ||
|
||
type VisionEngineModules = typeof _VisionEngineModules[number]; | ||
|
||
interface VisionEngineParams { | ||
image: string; | ||
imageBackground: string; | ||
module: VisionEngineModules; | ||
question?: string; | ||
websiteURL?: string; | ||
} | ||
|
||
/** | ||
* @classdesc OCR VisionEngine | ||
* @class | ||
* @extends {BaseTask} | ||
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html} | ||
*/ | ||
export class VisionEngine extends BaseTask implements VisionEngineParams, _IsTaskType { | ||
|
||
/** | ||
* @type {boolean} _isVisionEngine - Only used for correct method overloading intellisense | ||
*/ | ||
readonly _isVisionEngine: _IsTaskType["_isVisionEngine"] = true; | ||
|
||
/** | ||
* Create VisionEngine | ||
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html} | ||
* @param {Object} params - VisionEngineParams | ||
* @param {string} [params.image] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) | ||
* @param {string} [params.imageBackground] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) | ||
* @param {string} [params.question] - required for "space_detection" module | ||
* @param {VisionEngineModules=} [params.module] - Specifies the module. | ||
* @param {string} [params.websiteURL] - Page source url to improve accuracy | ||
*/ | ||
constructor({ | ||
image, imageBackground, question, module, websiteURL | ||
}: VisionEngineParams) { | ||
super({ type: "VisionEngine" }); | ||
this.image = image; | ||
this.imageBackground = imageBackground; | ||
this.question = question; | ||
this.module = module; | ||
this.websiteURL = websiteURL; | ||
} | ||
|
||
/** | ||
* @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) | ||
*/ | ||
image: string; | ||
|
||
/** | ||
* @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) | ||
*/ | ||
imageBackground: string; | ||
|
||
/** | ||
* @type {VisionEngineModules=} module - Specifies the module | ||
* {@see https://docs.capsolver.com/guide/recognition/VisionEngine.html} | ||
*/ | ||
module: VisionEngineModules; | ||
|
||
/** | ||
* @param {string} question - required for "space_detection" module | ||
*/ | ||
question?: string; | ||
|
||
/** | ||
* @type {string} websiteURL - Page source url to improve accuracy | ||
*/ | ||
websiteURL?: string; | ||
} |
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,13 +1,15 @@ | ||
import type { AwsWafClassification } from "./AwsWafClassification"; | ||
import type { FunCaptchaClassification } from "./FunCaptchaClassification"; | ||
import type { HCaptchaClassification } from "./HCaptchaClassification"; | ||
import type { ImageToTextTask } from "./ImageToTextTask"; | ||
import type { ReCaptchaV2Classification } from "./ReCaptchaV2Classification"; | ||
import { AwsWafClassification } from "./AwsWafClassification"; | ||
import { FunCaptchaClassification } from "./FunCaptchaClassification"; | ||
import { HCaptchaClassification } from "./HCaptchaClassification"; | ||
import { ImageToTextTask } from "./ImageToTextTask"; | ||
import { ReCaptchaV2Classification } from "./ReCaptchaV2Classification"; | ||
import { VisionEngine } from "./VisionEngine"; | ||
|
||
export { | ||
AwsWafClassification, | ||
FunCaptchaClassification, | ||
HCaptchaClassification, | ||
ImageToTextTask, | ||
ReCaptchaV2Classification | ||
ReCaptchaV2Classification, | ||
VisionEngine | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
capsolver/src/lib/Solution/Classification/VisionEngineSolution.ts
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,17 @@ | ||
|
||
interface VisionEngineAngleSolution { | ||
angle: number; | ||
} | ||
|
||
interface VisionEngineDistanceSolution { | ||
distance: number; | ||
} | ||
|
||
interface VisionEngineSpaceDetectionSolution { | ||
box: number[]; | ||
} | ||
|
||
/** | ||
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html#example-response} | ||
*/ | ||
export type VisionEngineSolution = VisionEngineAngleSolution & VisionEngineDistanceSolution & VisionEngineSpaceDetectionSolution; |
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,13 +1,15 @@ | ||
import type { AwsWafClassificationSolution } from "./AwsWafClassificationSolution"; | ||
import type { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution"; | ||
import type { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution"; | ||
import type { ImageToTextSolution } from "./ImageToTextSolution"; | ||
import type { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution"; | ||
import { VisionEngineSolution } from "./VisionEngineSolution"; | ||
import { AwsWafClassificationSolution } from "./AwsWafClassificationSolution"; | ||
import { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution"; | ||
import { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution"; | ||
import { ImageToTextSolution } from "./ImageToTextSolution"; | ||
import { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution"; | ||
|
||
export { | ||
AwsWafClassificationSolution, | ||
FunCaptchaClassificationSolution, | ||
HCaptchaClassificationSolution, | ||
ImageToTextSolution, | ||
ReCaptchaV2ClassificationSolution | ||
ReCaptchaV2ClassificationSolution, | ||
VisionEngineSolution | ||
}; |
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
42 changes: 42 additions & 0 deletions
42
capsolver/src/tests/Requests/Classification/VisionEngine.spec.ts
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,42 @@ | ||
import { VisionEngine } from "../../../lib/Requests/Classification/VisionEngine"; | ||
|
||
describe("VisionEngine Test", () => { | ||
it("To be equal to object", () => { | ||
const task = new VisionEngine({ | ||
image: "image-base64", | ||
imageBackground: "imageBackground-base64", | ||
module: "rotate_1", | ||
question: "question", | ||
websiteURL: "https://some-url.com" | ||
}); | ||
|
||
expect(task).toEqual({ | ||
_endpoint: "createTask", | ||
_isVisionEngine: true, | ||
image: "image-base64", | ||
imageBackground: "imageBackground-base64", | ||
module: "rotate_1", | ||
question: "question", | ||
type: "VisionEngine", | ||
websiteURL: "https://some-url.com" | ||
}); | ||
}); | ||
it("To be equal to object without optional params", () => { | ||
const task = new VisionEngine({ | ||
image: "image-base64", | ||
imageBackground: "imageBackground-base64", | ||
module: "rotate_1" | ||
}); | ||
|
||
expect(task).toEqual({ | ||
_endpoint: "createTask", | ||
_isVisionEngine: true, | ||
image: "image-base64", | ||
imageBackground: "imageBackground-base64", | ||
module: "rotate_1", | ||
question: undefined, | ||
type: "VisionEngine", | ||
websiteURL: undefined | ||
}); | ||
}); | ||
}); |