關於用php,OCR辨識圖片表格,怎麼能辨識出來的圖片完整的以原來格式顯示
P粉269094165
P粉269094165 2023-08-09 19:24:08
0
0
209

這是我的原始程式碼:

<?php


#/**

 * Post請求

 *

 * @param string $url 位址

 * @param array $headers Http Header

 * @param string $body 內容

 * @return string

 */


#function post($url, $headers, $body) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CUR##Lbody), $URDS_setopt($ch, CUR##3);

##    $response = curl_exec($ch);

    curl_close($ch);

    return $response;

}


// 請登入後前往「工作台-帳號設定-開發者資訊」 查看x-ti-app-id

// 範例程式碼中x-ti-app- id 非真實資料

const APP_ID = '9d285d1c896';

// 請登入後前往「工作台-帳號設定-開發者資訊」 檢視x-ti-secret-code

// 範例程式碼中x-ti-secret-code 非真實資料

const SECRET_CODE = '7be1f6203f';

// 通用表格識別

#const URL = 'https://api.textin.com/ai/service/v2/recognize/table';


$headers = [

##    ' x-ti-app-id:' . APP_ID,

    'x-ti-secret-code:' .  SECRET_CODE

];

$fileData = file_get_contents(' 123.png', false, stream_context_create([

    'http' => [

        'header' => 'Content-Type: image/png\r\n'##\r\n'

    ]

]));

$response = post(URL, $headers, $fileData);

$ocrResult = json_decode($response, true );


function displayTable($table) {

    echo "<table border='1'>";

foreach ($table as $row) {

        echo "<tr>";

        foreach ($row as $cell) {

#o# ; " . $cell[0]['text'] . "</td>";

        }

        echo "</tr>";

##      echo "</tr>";

##    }#   

    echo "</table>";

}

$table = $ocrResult['result']['tables '][0]['table_cells'];

displayTable($table);

$ocrResult多維數組函數,能正確取得到,但是以原來的格式,在螢幕上顯示表格及內容,不行,

這是辨識出來的部份表格內容:

array(5) { ["code"]=>; int(200) ["訊息"]=>字串(7)“成功”[“持續時間”]=> int(289) ["結果"]=>數組(4){ [“角度”] => int(0) ["高度"]=> int(219) ["表格"]=>數組(1) { [0]=>;數組(8){ [“行高”]=>數組(6) { [0]=>; int(46)[1]==> int(17) [2]==> int(29) [3]==> int(32) [4]==> int(20)[5]==> int(20) } ["型別"]=>字串(15)“table_with_line”[“table_cells”]=>數組(55) { [0]=>;數組(8) { ["end_row"]=>; int(0) ["邊框"]==>數組(4) { ["右"]=>; int(-1) ["底部"]=> int(-1) ["左"]=> int(-1) ["頂部"]=> int(-1) } ["位置"]=>數組(8) { [0]=>; int(1) [1]=> int(49) [2]==> int(635) [3]==> int(49) [4]==> int(635)[5]==> int(95)[6]==> int(1) [7]==> int(95) } ["end_col"]=>; int(11) ["開始行"]=> int(0) ["start_col"]=> int(0) ["行數"]=>數組(1) { [0]=>;數組(7){ [“角度”] => int(0) ["文本"]=> string(6) "宋體" ["方向"]=> int(1) ["手寫"]=> int(0) ["位置"]=>數組(8) { [0]=>; int(7) [1]==> int(60) [2]==> int(29) [3]==> int(60)[4]==> int(29)[5]==> int(73)[6]==> int(7) [7]==> int(73) } ["分數"]=>浮動(0.845)[“類型”]=> string(4) "文本" } } ["文本"]=> string(6) "宋體" } [1]=>數組(8) { ["end_row"]=>; int(1) ["邊框"]==>數組(4) { ["右"]=>; int(-1) ["底部"]=> int(-1) ["左"]=> int(-1) ["頂部"]=> int(-1) } ["位置"]=>數組(8) { [0]=>; int(2) [1]==> int(95)[2]==> int(26) [3]==> int(95)[4]==> int(26) [5]==> int(112) [6]==> int(2) [7]==> int(112) } ["end_col"]=>; int(0) ["開始行"]=> int(1) ["start_col"]=> int(0) ["行數"]=>數組(0) { } ["文本"]=>字串(0) "" } [2]=>數組(8) { ["end_row"]=>; int(1) ["邊框"]==>數組(4) { ["右"]=>; int(-1) ["底部"]=> int(-1) ["左"]=> int(-1) ["頂部"]=> int(-1) } ["位置"]=>數組(8) { [0]=>; int(26) [1]==> int(95)[2]==> int(84) [3]==> int(95)[4]==> int(84)[5]==> int(112) [6]==> int(26) [7]==>整數(112)}[“end_col”] => int(1) ["start_row"]=>; int(1) ["start_col"]=> int(1) ["行數"]=>數組(1) { [0]=>;數組(7){ [“角度”] => int(0) ["文本"]=>字串(1)“A”[“方向”]=> int(0) ["手寫"]=> int(0) ["位置"]=>數組(8) { [0]=>; int(49)[1]==> int(100) [2]==> int(61) [3]==> int(100) [4]=> int(61)[5]==> int(112) [6]==> int(49)[7]==> int(112) } ["分數"]=>浮動(0.849)[“類型”]=> string(4) "文本" } } ["文本"]=>字串(1) "A" } [3]=>數組(8) { ["end_row"]=>; int(1) ["邊框"]==>數組(4) { ["右"]=>; int(-1) ["底部"]=> int(-1) ["左"]=> int(-1) ["頂部"]=> int(-1) } ["位置"]=>數組(8) { [0]=>; int(84)[1]==> int(95)[2]==> int(150) [3]==> int(95)[4]==> int(150) [5]==> int(112) [6]==> int(84)[7]==> int(112) } ["end_col"]=>; int(2) ["start_row"]=> int(1) ["start_col"]=> int(2) ["行數"]=>數組(1) { [0]=>;數組(7){ [“角度”] => int(0) ["文本"]=> string(1) "B" ["方向


#
P粉269094165
P粉269094165

全部回覆(0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!