Google Cloud Vision APIのOCR(画像認識)★
Google Cloud Vision APIのOCR(画像認識)を検証する
http://qiita.com/keki/items/e5b82c6b4c28d3f00b72
参考
# cd /var/www/html/OCR_20170820
http://153.126.154.106/OCR_20170820/20170820_input.html
■APIキーの取得
https://console.developers.google.com/
今のKeyそのまま使えるかも・・・
AIzaSyCK*********************d87VGWc
■サンプル(拝借・・)
—————————–
20170820_test1.php
http://153.126.154.106/OCR_20170820/20170820_test1.php
—————————–
 array(
                        array(
                                “image” => array(
                                        “content” => base64_encode(file_get_contents($imageNm)),
                                ),
                                “features” => array(
                                        array(
                                                “type” => “TEXT_DETECTION”,
                                                “maxResults” => 10,
                                        ),
                                ),
                        ),
                ),
        ));
        // 各種オプションを設定
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, “https://vision.googleapis.com/v1/images:annotate?key=” . $apiKey); // Google Cloud Vision APIのURLを設定
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_execの結果を文字列で取得
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // サーバ証明書の検証を行わない
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”); // POSTでリクエストする
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-Type: application/json”)); // 送信するHTTPヘッダーの設定
        curl_setopt($curl, CURLOPT_TIMEOUT, 15); // タイムアウト時間の設定(秒)
        curl_setopt($curl, CURLOPT_POSTFIELDS, $json); // 送信するjsonデータを設定
        // curl実行
        $res = curl_exec($curl);
        $data = json_decode($res, true);
        curl_close($curl);
        // 結果を表示
        print $data[“responses”][0][“fullTextAnnotation”][“text”];
—————————–
おおお!、いきなりOK!!
ありがとうございます。
さて、input.htmlとつなげるphpにしてupload.phpを作成するか・・・
http://153.126.154.106/OCR_20170820/20170820_input.html
からアクセスして引き継ぐ・・・
結果、以下
—————————–
20170820_test1.php
http://153.126.154.106/OCR_20170820/20170820_OCR_up.php
—————————–
 array(
                        array(
                                “image” => array(
                                        “content” => base64_encode(file_get_contents($imageNm)),
                                ),
                                “features” => array(
                                        array(
                                                “type” => “TEXT_DETECTION”,
                                                “maxResults” => 10,
                                        ),
                                ),
                        ),
                ),
        ));
        // 各種オプションを設定
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, “https://vision.googleapis.com/v1/images:annotate?key=” . $apiKey); // Google Cloud Vision APIのURLを設定
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_execの結果を文字列で取得
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // サーバ証明書の検証を行わない
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”); // POSTでリクエストする
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-Type: application/json”)); // 送信するHTTPヘッダーの設定
        curl_setopt($curl, CURLOPT_TIMEOUT, 15); // タイムアウト時間の設定(秒)
        curl_setopt($curl, CURLOPT_POSTFIELDS, $json); // 送信するjsonデータを設定
        // curl実行
        $res = curl_exec($curl);
        $data = json_decode($res, true);
        curl_close($curl);
        // 結果を表示
        print $data[“responses”][0][“fullTextAnnotation”][“text”];