หน้าแรก เอกสาร บทช่วยสอน ลงชื่อเข้าใช้
ประเภทงานที่รองรับ
เมธอด API
บทความ
บทช่วยสอน
GitHub
เมนูเอกสาร

ImageToTextTask : แก้ Captcha แบบรูปภาพ

โพสต์เนื้อหารูปภาพและรับข้อความจากนั้น ข้อความต้องเป็นตัวเลข ตัวอักษร อักขระพิเศษและช่องว่างเท่านั้น รองรับภาพเคลื่อนไหว GIF สูงสุด 500kb, Captcha ที่กำหนดเอง เช่น "ค้นหาแมวในชุดรูปภาพนี้ และป้อนหมายเลข" ไม่รองรับ

อ็อบเจ็กต์งาน

คุณสมบัติ ประเภท จำเป็น ค่าเริ่มต้น วัตถุประสงค์
type สตริง ใช่ ImageToTextTask กำหนดประเภทของงาน
body สตริง ใช่ เนื้อหาไฟล์ที่เข้ารหัสใน base64 อย่าลืมส่งโดยไม่มีการแบ่งบรรทัด อย่าใส่ 'data:image/png,' หรือแท็กที่คล้ายกัน ให้ล้างเฉพาะ base64 เท่านั้น!
phrase บูลีน ไม่ false false - ไม่มีข้อกำหนด
true - ต้องการให้คนงานป้อนคำตอบโดยมี "ช่องว่าง"อย่างน้อยหนึ่งช่อง หากไม่มีช่องว่าง คนงานจะข้ามงานไป ดังนั้นโปรดใช้ด้วยความระมัดระวัง
case บูลีน ไม่ true false - ไม่มีข้อกำหนด
true - คนงานจะเห็นเครื่องหมายพิเศษบอกว่าต้องป้อนคำตอบโดยคำนึงถึงตัวพิมพ์เล็กและใหญ่
numeric จำนวนเต็ม ไม่ 0 0 - ไม่มีข้อกำหนด
1 - อนุญาตให้ใช้ตัวเลขเท่านั้น
2 - อนุญาตให้ใช้ตัวอักษรใดก็ได้ ยกเว้นตัวเลข
math บูลีน ไม่ false false - ไม่มีข้อกำหนด
true - คนงานจะเห็นเครื่องหมายพิเศษบอกว่าต้องคำนวณคำตอบนั้น
minLength จำนวนเต็ม ไม่ 0 0 - ไม่มีข้อกำหนด
>1 - กำหนดความยาวขั้นต่ำของคำตอบ
maxLength จำนวนเต็ม ไม่ 0 0 - ไม่มีข้อกำหนด
>1 - กำหนดความยาวสูงสุดของคำตอบ
comment สตริง ไม่ ความคิดเห็นเพิ่มเติมสำหรับคนงาน เช่น "ป้อนตัวอักษรด้วยสีแดง"
ไม่รับประกันผลลัพธ์และขึ้นอยู่กับคนงานโดยสิ้นเชิง
websiteURL สตริง ไม่ พารามิเตอร์ทางเลือกในการแยกแยะแหล่งที่มาของ Captcha แบบรูปภาพในสถิติการใช้จ่าย

ตัวอย่างคำขอ

CURL
          curl -i -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -X POST -d '{
    "clientKey":"YOUR_API_KEY_HERE",
    "task":
        {
            "type":"ImageToTextTask",
            "body":"BASE64_BODY_HERE__NO_NEWLINES__NO_EXTRA_TAGS__ONLY_CLEAN_BASE64",
            "phrase":false,
            "case":false,
            "numeric":0,
            "math":false,
            "minLength":0,
            "maxLength":0
        },
    "softId": 0
}' https://api.anti-captcha.com/createTask
        
PHP
          <?php

//git clone git@github.com:AdminAnticaptcha/anticaptcha-php.git

include("anticaptcha.php");
include("imagetotext.php");

$api = new ImageToText();

//your anti-captcha.com account key
$api->setKey("YOUR_API_KEY_HERE");

//setting file
$api->setFile("captcha.jpg");

//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
$api->setSoftId(0);

//create task in API
if (!$api->createTask()) {
    echo "API v2 send failed - ".$api->getErrorMessage()."\n";
    exit;
}

$taskId = $api->getTaskId();

if (!$api->waitForResult()) {
    echo "could not solve captcha\n";
    echo $api->getErrorMessage()."\n";
} else {
    $captchaText    =   $api->getTaskSolution();
    echo "captcha text: $captchaText\n\n";
}
        
Python
          #pip3 install anticaptchaofficial

from anticaptchaofficial.imagecaptcha import *

solver = imagecaptcha()
solver.set_verbose(1)
solver.set_key("YOUR_API_KEY_HERE")

# Specify softId to earn 10% commission with your app.
# Get your softId here: https://anti-captcha.com/clients/tools/devcenter
solver.set_soft_id(0)

captcha_text = solver.solve_and_return_solution("captcha.jpeg")
if captcha_text != 0:
    print "captcha text "+captcha_text
else:
    print "task finished with error "+solver.error_code
        
NodeJS
          //npm install @antiadmin/anticaptchaofficial
//https://github.com/AdminAnticaptcha/anticaptcha-npm

const ac = require("@antiadmin/anticaptchaofficial");
const fs = require('fs');

const captcha = fs.readFileSync('captcha.png', { encoding: 'base64' });

ac.setAPIKey('YOUR_API_KEY_HERE');

//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
ac.setSoftId(0);

ac.solveImage(captcha, true)
    .then(text => console.log('captcha text: '+text))
    .catch(error => console.log('test received error '+error));
        
C#
          //git clone git@github.com:AdminAnticaptcha/anticaptcha-csharp

using System;
using Anticaptcha_example.Api;
using Anticaptcha_example.Helper;
using Newtonsoft.Json.Linq;

namespace Anticaptcha_example
{
    internal class Program
    {
        private static void Main() {

            DebugHelper.VerboseMode = true;

            var api = new ImageToText
            {
                ClientKey = "YOUR_API_KEY_HERE",
                FilePath = "captcha.jpg",
                // Specify softId to earn 10% commission with your app.
                // Get your softId here:
                // https://anti-captcha.com/clients/tools/devcenter
                SoftId = 0
            };

            if (!api.CreateTask())
                DebugHelper.Out("API v2 send failed. " + api.ErrorMessage, DebugHelper.Type.Error);
            else if (!api.WaitForResult())
                DebugHelper.Out("Could not solve the captcha.", DebugHelper.Type.Error);
            else
                DebugHelper.Out("Result: " + api.GetTaskSolution().Text, DebugHelper.Type.Success);

        }
    }
}

        
Java
          //git clone git@github.com:AdminAnticaptcha/anticaptcha-java.git

package com.anti_captcha;

import com.anti_captcha.Api.ImageToText;
import com.anti_captcha.Helper.DebugHelper;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;

public class Main {

    public static void main(String[] args) throws InterruptedException, MalformedURLException, JSONException {
        DebugHelper.setVerboseMode(true);

        ImageToText api = new ImageToText();
        api.setClientKey("YOUR_API_KEY_HERE");
        api.setFilePath("captcha.jpg");

        //Specify softId to earn 10% commission with your app.
        //Get your softId here: https://anti-captcha.com/clients/tools/devcenter
        api.setSoftId(0);

        if (!api.createTask()) {
            DebugHelper.out(
                    "API v2 send failed. " + api.getErrorMessage(),
                    DebugHelper.Type.ERROR
            );
        } else if (!api.waitForResult()) {
            DebugHelper.out("Could not solve the captcha.", DebugHelper.Type.ERROR);
        } else {
            DebugHelper.out("Result: " + api.getTaskSolution().getText(), DebugHelper.Type.SUCCESS);
        }
    }

}
        

ตัวอย่างการตอบกลับ

JSON ที่ไม่มีข้อผิดพลาด
          {
    "errorId": 0,
    "taskId": 7654321
}
        
JSON ที่มีข้อผิดพลาด
          {
    "errorId": 1,
    "errorCode": "ERROR_KEY_DOES_NOT_EXIST",
    "errorDescription": "Account authorization key not found in the system"
}
        

เรียกดูโซลูชัน

ใช้เมธอด getTaskResult เพื่อขอโซลูชัน โดยให้เวลาคนงานสัก 5 วินาทีก่อนส่งคำขอครั้งแรก หากคนงานยังไม่ว่าง ให้ลองอีกครั้งใน 3 วินาที

อ็อบเจ็กต์โซลูชันงาน

คุณสมบัติ ประเภท วัตถุประสงค์
text สตริง ข้อความจาก Captcha แบบรูปภาพ
url สตริง ที่อยู่เว็บของ Captcha ซึ่งเราจะเก็บให้ 24 ชั่วโมงและจะลบออกหลังจากนั้น

ตัวอย่างการตอบกลับ

JSON ที่ไม่มีข้อผิดพลาด
          {
    "errorId":0,
    "status":"ready",
    "solution":
    {
        "text":"deditur",
        "url":"http://61.39.233.233/1/147220556452507.jpg"
    },
    "cost":"0.000700",
    "ip":"46.98.54.221",
    "createTime":1472205564,
    "endTime":1472205570,
    "solveCount":"0"
}