在Codeigniter中使用Google Cloud Vision,找不到Class ImageAnnotatorCl



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

我已经将作曲家从谷歌云视觉安装到代码中的第三方供应商。

我在结构中的设置是:

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();
            }
        }
    }

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

致命错误:找不到类"图像注释器客户端">

这是哪一行:

$imageAnnotator = new ImageAnnotatorClient([

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

我在这里错过了什么吗?

谢谢

这就是答案。

检查这篇文章: PHP CodeIgniter 框架中的命名空间

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

最新更新