laravel 检测sql

by Darren Chowles

达伦·乔尔斯(Darren Chowles)

在Laravel PHP应用程序中轻松进行面部检测 (Easy facial detection in your Laravel PHP application)

使用Google Cloud Vision API检测图像中的人脸 (Detect faces in images using the Google Cloud Vision API)

You’ve probably seen facial detection before. As soon as you upload that family photo to Facebook, you’ll notice the boxes around all detected faces. And with facial recognition, it sometimes even auto-tags the correct friend too. It’s not always 100% accurate, but it’s still some great engineering!

您可能以前曾经看过面部检测。 将家庭照片上传到Facebook后,您会注意到所有检测到的脸Kong周围的方框。 有了面部识别功能 ,它有时甚至还会自动标记正确的朋友。 它并不总是100%准确,但是仍然是一些很棒的工程!

面部检测应用 (Applications for facial detection)

In this article, we’ll get up and running using the Google Cloud Vision API to detect faces. We’ll be using an existing image and we’ll draw a box around each detected face.

在本文中,我们将使用Google Cloud Vision API进行检测并开始运行。 我们将使用现有图像,并在每个检测到的脸部周围绘制一个方框。

There are several real-world use cases for facial detection. Some of these include:

有几种现实世界的面部检测用例。 其中一些包括:

  • detecting whether an uploaded image has any faces. This might be a screening step as part of a “know your customer” identification workflow.检测上传的图像是否有脸Kong。 这可能是“了解您的客户”识别工作流程一部分的筛选步骤。
  • image moderation for applications that allow user-generated content.允许用户生成内容的应用程序的图像审核。
  • the ability to provide tagging, in the same way social networks do.具有与社交网络相同的方式提供标记的功能。

Cloud Vision API中可用的其他功能 (Other functionality available in the Cloud Vision API)

Facial detection is only one of the many functions available in this API. It supports the following additional functionality:

面部检测只是此API中可用的众多功能之一。 它支持以下附加功能:

  • detection of popular logos.检测流行徽标。
  • the ability to detect all categories applicable to an image. For example, a photo of a cat might produce the categories: cat, mammal, vertebrate, and Persian.检测适用于图像的所有类别的能力。 例如,猫的照片可能会产生以下类别:猫,哺乳动物,脊椎动物和波斯。
  • detecting popular natural and man-made landmarks.检测流行的自然和人造地标。
  • extracting text from images.从图像中提取文本。
  • running Safe Search Detection to flag images that contain adult content or violence.运行安全搜索检测以标记包含成人内容或暴力内容的图像。

Google Cloud Platform设定 (Google Cloud Platform setup)

The first step involves creating a new project in the Google Cloud Platform console.

第一步涉及在Google Cloud Platform控制台中创建一个新项目。

Head over to the dashboard and create a new project.

转到仪表板并创建一个新项目 。

Once your project is created, keep the Project ID handy.

创建项目后,请随时保留项目ID。

Follow these steps:

跟着这些步骤:

  • once you have your project, go to the Create service account key page.

    完成项目后,转到“ 创建服务帐户密钥”页面。

  • ensure your Facial Detection project is selected at the top.确保在顶部选择了面部检测项目。
  • under “Service account, select “New service account”.

    在“服务帐户”下 ,选择“新服务帐户”。

  • enter a name in the “Service account name”.在“服务帐户名称”中输入名称。
  • under “Role”, select “Project” > “Owner”.在“角色”下,选择“项目”>“所有者”。
  • Finally, click “Create” to have the JSON credentials file downloaded automatically.最后,单击“创建”以自动下载JSON凭证文件。

You may also need to Enable the Cloud Vision API via the API Library section.

您可能还需要通过“ API库”部分启用Cloud Vision API。

Laravel项目设置 (Laravel project setup)

The next step involves setting up a new Laravel project. If you have an existing Laravel project, you can skip this step.

下一步涉及建立一个新的Laravel项目。 如果您已经有一个Laravel项目,则可以跳过此步骤。

I’m using Laravel 5.5 LTS for this article. In the command line, run the following Composer command to create a new project (you can also use the Laravel installer):

我在本文中使用Laravel 5.5 LTS。 在命令行中,运行以下Composer命令以创建一个新项目(您也可以使用Laravel安装程序 ):

composer create-project --prefer-dist laravel/laravel sample "5.5.*"

If you used Composer, rename the .env.example file to .env and run the following command afterwards to set the application key:

如果您使用的作曲家,重命名.env.example文件.ENV事后运行以下命令来设置应用程序键:

php artisan key:generate

添加Google Cloud-vision软件包 (Add the Google cloud-vision package)

Run the following command to add the google/cloud-vision package to your project:

运行以下命令以将google/cloud-vision包添加到您的项目中:

composer require google/cloud-vision

You can place the downloaded JSON credentials file in your application root. Don’t place it in your public directory. Feel free to rename it. Don’t commit this file to your code repo. One option is to add it to the server manually.

您可以将下载的JSON凭证文件放置在应用程序根目录中。 不要将其放在您的公共目录中。 随时重命名。 不要将此文件提交到您的代码存储库中。 一种选择是将其手动添加到服务器。

最后,让我们开始编码! (Finally, let’s start coding!)

Firstly, ensure you have the GD library installed and active. Most platforms have this enabled by default.

首先,请确保已安装并激活了GD库 。 大多数平台默认情况下都启用了此功能。

I’ll be adding the following route to my “routes/web.php” file:

我将以下路由添加到“ routes / web.php”文件中:

Route::get('/', 'SampleController@detectFaces');

I’ve created a simple controller to house the code. I’ll be adding all the code within the controller. In a production application, I strongly suggest using separate service classes for any business logic. This way, controllers are lean and stick to their original intention: controlling the input/output.

我创建了一个简单的控制器来存放代码。 我将在控制器中添加所有代码。 在生产应用程序中,我强烈建议对任何业务逻辑使用单独的服务类。 这样,控制器就会精简并坚持其原始意图:控制输入/输出。

We’ll start with a simple controller, adding a use statement to include the Google Cloud ServiceBuilder class:

我们将从一个简单的控制器开始,添加一个use语句以包括Google Cloud ServiceBuilder类:

<?php
namespace App\Http\Controllers;
use Google\Cloud\Core\ServiceBuilder;
class SampleController extends Controller{    public function detectFaces()    {        // Code will be added here    }}

The first thing we’ll do is create an instance of the ServiceBuilder class so we can specify our Project ID and JSON credentials.

我们要做的第一件事是创建ServiceBuilder类的实例,以便我们可以指定项目ID和JSON凭据。

$cloud = new ServiceBuilder([     'keyFilePath' => base_path('fda.json'),     'projectId' => 'facial-detection-app' ]);

You specify the location of the JSON file using the keyFilePath key. I’ve used the Laravel base_path() helper to refer to the fully qualified app root path.

您可以使用keyFilePath键指定JSON文件的位置。 我使用了Laravel base_path()帮助器来引用完全限定的应用程序根路径。

The next option is the projectId. This is the value you grabbed when you created the project in the GCP console.

下一个选项是projectId 。 这是在GCP控制台中创建项目时获取的值。

Next, we’ll create an instance of the VisionClient class. The ServiceBuilder class makes it easy by exposing various factory methods which grant access to services in the API.

接下来,我们将创建VisionClient类的实例。 通过公开各种工厂方法(可授予对API中服务的访问权限), ServiceBuilder类可轻松实现。

$vision = $cloud->vision();

Now that we have an instance of the class, we can start making use of the Vision API. We’ll be using the following image as the example. Feel free to download this image, name it “friends.jpg” and place it in your “public” folder.

现在我们有了该类的实例,我们可以开始使用Vision API。 我们将使用以下图像作为示例。 可以免费下载此图像,将其命名为“ friends.jpg”,并将其放置在“ public”文件夹中。

We’ll first create a new image using the GD imagecreatefromjpeg() function. We’ll use the public_path() Laravel helper to refer to our image placed in the “public” folder.

我们将首先使用GD imagecreatefromjpeg()函数创建一个新图像。 我们将使用public_path() Laravel帮助器来引用放置在“ public”文件夹中的图像。

$output = imagecreatefromjpeg(public_path('friends.jpg'));

Next, we’ll create a Cloud Vision Image object with this same image and specify that we want to run facial detection:

接下来,我们将使用相同的图像创建一个Cloud Vision Image对象,并指定我们要运行面部检测:

$image = $vision->image(file_get_contents(public_path('friends.jpg')), ['FACE_DETECTION']);

You’ll notice a slight change here. Instead of providing the path to the image, we’re supplying the actual image as a string using file_get_contents().

您会在这里看到一些细微的变化。 除了提供图像的路径,我们使用file_get_contents()将实际图像作为字符串提供。

Then we run the annote() method on the image:

然后,在图像上运行annote()方法:

$results = $vision->annotate($image);

Now that we have the results, we simply need to loop through the found faces and draw boxes around the them using the vertices supplied in the result:

现在我们有了结果,我们只需要遍历找到的面并使用结果中提供的顶点在它们周围画框:

foreach ($results->faces() as $face) {    $vertices = $face->boundingPoly()['vertices'];
$x1 = $vertices[0]['x'];    $y1 = $vertices[0]['y'];    $x2 = $vertices[2]['x'];    $y2 = $vertices[2]['y'];
imagerectangle($output, $x1, $y1, $x2, $y2, 0x00ff00);}

Once this is done, we can output the image and destroy it to free up the memory:

完成此操作后,我们可以输出图像并销毁它以释放内存:

header('Content-Type: image/jpeg'); imagejpeg($output); imagedestroy($output);

And this is the result:

结果如下:

Here is the final controller class code:

这是最终的控制器类代码:

<?php
namespace App\Http\Controllers;
use Google\Cloud\Core\ServiceBuilder;
class SampleController extends Controller{    public function detectFaces()    {        $cloud = new ServiceBuilder([            'keyFilePath' => base_path('fda.json'),            'projectId' => 'facial-detection-app'        ]);
$vision = $cloud->vision();
$output = imagecreatefromjpeg(public_path('friends.jpg'));        $image = $vision->image(file_get_contents(public_path('friends.jpg')), ['FACE_DETECTION']);        $results = $vision->annotate($image);
foreach ($results->faces() as $face) {            $vertices = $face->boundingPoly()['vertices'];
$x1 = $vertices[0]['x'];            $y1 = $vertices[0]['y'];            $x2 = $vertices[2]['x'];            $y2 = $vertices[2]['y'];
imagerectangle($output, $x1, $y1, $x2, $y2, 0x00ff00);        }
header('Content-Type: image/jpeg');
imagejpeg($output);        imagedestroy($output);    }}

附加功能 (Additional functionality)

In addition to grabbing the vertices, the response also includes a trove of useful information. This includes the locations of mouths, eyes, eyebrows, noses, etc. Simply print_r() the $face variable for a quick peek into the available data.

除了获取顶点之外,响应还包括大量有用的信息。 这包括嘴巴,眼睛,眉毛,鼻子等的位置。只需print_r() $face变量,即可快速浏览可用数据。

Another great feature is checking whether the detected face is happy, sad, angry, or surprised. You can even detect whether the face is blurry or underexposed, and whether they’re wearing headwear.

另一个重要功能是检查检测到的脸部是高兴,悲伤,生气还是惊讶。 您甚至可以检测出脸部是否模糊或曝光不足,以及他们是否戴着头饰。

If you use this and end up doing something cool as a result, please let me know!

如果您使用它并最终做一些很酷的事情,请告诉我!

升级您的Web开发技能! (Upgrade your web dev skills!)

Sign up to my newsletter where I’ll share insightful web development articles to supercharge your skills.

注册我的时事通讯 ,我将在其中分享有见地的Web开发文章,以增强您的技能。

Originally published at www.chowles.com on July 6, 2018.

最初于2018年7月6日发布在www.chowles.com上。

翻译自: https://www.freecodecamp.org/news/easy-facial-detection-in-your-laravel-php-application-11664ac9c9b9/

laravel 检测sql

laravel 检测sql_在Laravel PHP应用程序中轻松进行面部检测相关推荐

  1. 小程序中轻松添加日期和时间的选择

    介绍 选择日期和时间,直接使用小程序的默认组件picker,就可以解决了. 选择日期:将mode设置为date 选择事件:将mode设置为time 注意:date和data经常容易被弄混,这里我特别强 ...

  2. laravel清理缓存(config:clear)后导致程序崩溃

    laravel清理缓存(config:clear)后导致程序崩溃 前情提要:导致这个错误的可能性有很多,如此不人性化的提示是因为在config:clear后laravel重载出错,然后尝试从log输出 ...

  3. laravel php resources,利用 Laravel Resources 来整合第三方 API 数据

    对于某些应用程序,可能需要第三方服务或者 API 来提取某些数据,将该数据转换为所需的响应,并将其传送到客户端界面. 为此,我们需要找到一种方法,方便从控制器发送到视图或最终用户界面的数据保持一致性. ...

  4. php laravel union,教程:Laravel 集合(Collection)的基础用法

    Laravel 集合是 Laravel 框架中一个十分有用的工具. Laravel 集合就像是在 PHP 中的数组,但会更好用. 在这篇教程中,我们将会体验一些集合使用时的实用技巧. 集合(Colle ...

  5. 【Tools】Linux下C和C++程序中内存泄露检测

    00. 目录 文章目录 00. 目录 01. 前言 02. valgrind安装 03. 使用未初始化的内存 04. 使用野指针 05. 动态内存越界访问 06. 分配空间后没有释放 07. 不匹配使 ...

  6. 监视和检测Java应用程序中的内存泄漏

    因此,您的应用程序内存不足,您日夜不停地分析应用程序,以期捕获对象中的内存漏洞. 后续步骤将说明如何监视和检测您的内存泄漏,以确保您的应用程序安全. 1.怀疑内存泄漏 如果您怀疑有内存泄漏,可以使用一 ...

  7. laravel框架——composer导入laravel

    第一种: composer create-project --prefer-dist laravel/laravel projectName "5.2.*"第二种: compose ...

  8. Laravel同时接收路由参数和查询字符串中的参数

    Laravel捕捉路由参数 Laravel允许在controller方法中捕捉路由里定义的参数,如下所示: 路由中定义参数: Route::get('post/{id}', 'PostControll ...

  9. laravel mysql 视图_视图入门:Laravel 支持的视图格式以及在路由中的基本使用

    视图入门:Laravel 支持的视图格式以及在路由中的基本使用 由 学院君 创建于2年前, 最后更新于 1年前 版本号 #2 19892 views 20 likes 0 collects Larav ...

最新文章

  1. linux中deb怎样安装
  2. 基于SSH框架实际开发时遇到的问题及解决办法
  3. java1.8 lambda进行并行运算
  4. 机器学习导论(张志华):多元高斯分布及应用
  5. 计算机网络全部实验,计算机网络综合实验
  6. android通讯录上传服务器,Android 实现读取通讯录并上传服务器
  7. Node — 第九天 (大事件项目接口实现三)
  8. 项目中的富文本编辑器该如何选择?
  9. jQuery实现页面关键词高亮
  10. linux系统用户迁移
  11. C#实现文件拖放并打开文件
  12. 面向 Android 软件开发套件(SDK)的 x86 Android* 系统映像许可协议
  13. sort 、sorted、range、join方法 数字的正序、倒叙、翻转
  14. 【微信小程序学习】小程序API
  15. icassp2021论文集下载
  16. 如何转型成为数据分析师
  17. 手机远程服务器rd,手机远程连接服务器工具:RD client远程桌面使用教程
  18. 深度操作系统20.6发布
  19. win7记事本如何转换html,Win7系统打开记事本文本文档出现乱码如何解决?
  20. 计算机视觉常用资源整理

热门文章

  1. 阿里巴巴Android面试都问些什么?系列篇
  2. 1.Swift教程翻译系列——关于Swift
  3. Convolutional neural networks for artistic style transfer
  4. easyui combox使用
  5. 解决FTPClient上传文件为空,显示0字节
  6. Jenkins的一些代码
  7. Anaconda安装tensorflow报错问题解决方法
  8. 2 Hadoop的安装与配置
  9. Flink DataStream 编程入门
  10. DRF数据验证+数据存储