【问题标题】:Use Google Cloud Vision in Codeigniter, Cannot Find Class ImageAnnotatorClient在 Codeigniter 中使用 Google Cloud Vision,找不到类 ImageAnnotatorClient
【发布时间】:2019-08-22 04:07:16
【问题描述】:

我想使用谷歌云视觉实现谷歌云视觉文本检测。

我已将来自 google cloud vision 的作曲家安装到 codeignier 中的第三方供应商。

我在构造中的设置是:

include APPPATH . 'third_party/vendor/autoload.php';
        require_once APPPATH.'third_party/vendor/google/cloud-vision/src/V1/ImageAnnotatorClient.php';          

我调用 OCR 的功能是:

function upload_ocr_image()
    {               
        if (count($_FILES) === 0) { echo 'no image received from unity'; }

        $phone_code = $this->input->post('phone_code', true);
        $phone_number = $this->input->post('phone_number', true);

        $allowedType = array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG);       
        $imgType = exif_imagetype($_FILES['ocr_image']['tmp_name']);

        if(!in_array($imgType,$allowedType))
        {
            echo "Images Type Error. Images Type Only : GIF , JPEG, PNG";
            exit;
        }
        else
        {

            //upload original size front end slider
            $config['upload_path'] = './assets/ocr_image/';
            $config['allowed_types'] = '*';
            $config['file_name'] = $phone_code.$phone_number.".jpg";
            $config['overwrite'] = TRUE;
            $config['max_size'] = '8096';
            $config['max_width']  = '8000';
            $config['max_height']  = '8000';


            $this->load->library('upload', $config);

            $this->upload->initialize($config);
            if(!$this->upload->do_upload("ocr_image"))
            {
                echo "Maximum File Size Only 2 Mb Or Max Width = 2000 , Height = 2000";
                exit;
            }
            else
            {
                $img_data = $this->upload->data();

                // Authenticating with a keyfile path.

                $imageAnnotator = new ImageAnnotatorClient([
                    'credentials' => base_url().'assets/google_cloud_vision/keyfile.json'
                ]);

                # annotate the image
                $response = $imageAnnotator->textDetection($img_data['full_path']);
                $texts = $response->getTextAnnotations();

                printf('%d texts found:' . PHP_EOL, count($texts));
                foreach ($texts as $text) {
                    print($text->getDescription() . PHP_EOL);

                    # get bounds
                    $vertices = $text->getBoundingPoly()->getVertices();
                    $bounds = [];
                    foreach ($vertices as $vertex) {
                        $bounds[] = sprintf('(%d,%d)', $vertex->getX(), $vertex->getY());
                    }
                    print('Bounds: ' . join(', ',$bounds) . PHP_EOL);
                }

                $imageAnnotator->close();

            }
        }
    }

但在处理文本检测之前我遇到了错误:

致命错误:找不到类“ImageAnnotatorClient”

这是哪一行:

$imageAnnotator = new ImageAnnotatorClient([

什么可能导致错误?从上面的构造中,我已经包含或 require_once 类的路径。

这里有什么我遗漏的吗?

谢谢

【问题讨论】:

标签: php codeigniter google-cloud-vision


【解决方案1】:

这就是答案。

查看此帖子:Namespace in PHP CodeIgniter Framework

只需在config.php底部添加检测命名空间的代码

【讨论】:

    猜你喜欢
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    相关资源
    最近更新 更多