search

Home  >  Q&A  >  body text

Regarding using php and OCR to identify image tables, how can the identified images be displayed completely in their original format?

This is my original code:

<?php


##/**

* Post request

*

* @param string $url address

* @param array $headers Http Header

* @param string $body content

* @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_HEADER, false);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);

curl_close($ch);

return $response;

}


// Please log in and go to "Workbench-Account Settings-Developer Information" to view x-ti-app-id

// In the sample code, x-ti-app- id is not real data

const APP_ID = '9d285d1c896';

// Please log in and go to "Workbench-Account Settings-Developer Information" to view x-ti-secret-code

//x-ti-secret-code in the sample code is not real data

const SECRET_CODE = '7be1f6203f';

//General table recognition

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'

]

]));

$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) {

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

       }

##                                                                                                                         

echo "</table>";

}

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

displayTable($table);

$ocrResult multi-dimensional array function can be obtained correctly, but Displaying the table and content on the screen in the original format does not work.

This is part of the recognized table content:

array(5) { ["code"]=> int(200) ["message"]=> string(7) "success" ["duration"]=> int(289) ["result"]=> array(4) { ["angle"]=> int(0) ["height"]=> int(219) ["tables"]=> array(1) { [0]=> array(8) { ["height_of_rows"]=> array(6) { [0]=> int(46) [1]=> int(17) [2]=> int(29) [3]=> int(32) [4]=> int(20) [5]=> int(20) } ["type"]=> string(15) "table_with_line" ["table_cells"]=> array(55) { [0]=> array(8) { ["end_row"]=> int(0) ["borders"]=> array(4) { ["right"]=> int(-1) ["bottom"]=> int(-1) ["left"]=> int(-1) ["top"]=> int(-1) } ["position"]=> array(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) ["start_row"]=> int(0) ["start_col"]=> int(0) ["lines"]=> array(1) { [0]=> array(7) { ["angle"]=> int(0) ["text"]=> string(6) "宋体" ["direction"]=> int(1) ["handwritten"]=> int(0) ["position"]=> array(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) } ["score"]=> float(0.845) ["type"]=> string(4) "text" } } ["text"]=> string(6) "宋体" } [1]=> array(8) { ["end_row"]=> int(1) ["borders"]=> array(4) { ["right"]=> int(-1) ["bottom"]=> int(-1) ["left"]=> int(-1) ["top"]=> int(-1) } ["position"]=> array(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) ["start_row"]=> int(1) ["start_col"]=> int(0) ["lines"]=> array(0) { } ["text"]=> string(0) "" } [2]=> array(8) { ["end_row"]=> int(1) ["borders"]=> array(4) { ["right"]=> int(-1) ["bottom"]=> int(-1) ["left"]=> int(-1) ["top"]=> int(-1) } ["position"]=> array(8) { [0]=> int(26) [1]=> int(95) [2]=> int(84) [3]=> int(95) [4]=> int(84) [5]=> int(112) [6]=> int(26) [7]=> int(112) }["end_col"]=> int(1) ["start_row"]=> int(1) ["start_col"]=> int(1) ["lines"]=> array(1) { [0]=> array(7) { ["angle"]=> int(0) ["text"]=> string(1) "A" ["direction"]=> int(0) ["handwritten"]=> int(0) ["position"]=> array(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) } ["score"]=> float(0.849) ["type"]=> string(4) "text" } } ["text"]=> string(1) "A" } [3]=> array(8) { ["end_row"]=> int(1) ["borders"]=> array(4) { ["right"]=> int(-1) ["bottom"]=> int(-1) ["left"]=> int(-1) ["top"]=> int(-1) } ["position"]=> array(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) ["lines"]=> array(1) { [0]=> array(7) { ["angle"]=> int(0) ["text"]=> string(1) "B" ["direction


P粉269094165P粉269094165549 days ago409

reply all(0)I'll reply

No reply
  • Cancelreply