在Codeigniter中使用Google Cloud Vision,无法找到类ImageAnnotatorClient

问题描述 投票:0回答:1

我想使用谷歌云视觉实现谷歌云视觉textDetection。

我已经将作者从谷歌云视觉安装到codeigniter中的第三方供应商。

我在构造中的设置是:

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个回答
0
投票

这就是答案。

看看这篇文章:Namespace in PHP CodeIgniter Framework

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

© www.soinside.com 2019 - 2024. All rights reserved.