laravel 检测sql_在Laravel PHP应用程序中轻松进行面部检测-程序员宅基地

技术标签: python  java  linux  php  人脸识别  

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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cumi7754/article/details/108157539

智能推荐

C#连接OPC C#上位机链接PLC程序源码 1.该程序是通讯方式是CSharp通过OPC方式连接PLC_c#opc通信-程序员宅基地

文章浏览阅读565次。本文主要介绍如何使用C#通过OPC方式连接PLC,并提供了相应的程序和学习资料,以便读者学习和使用。OPC服务器是一种软件,可以将PLC的数据转换为标准的OPC格式,允许其他软件通过标准接口读取或控制PLC的数据。此外,本文还提供了一些学习资料,包括OPC和PLC的基础知识,C#编程语言的教程和实例代码。这些资料可以帮助读者更好地理解和应用本文介绍的程序。1.该程序是通讯方式是CSharp通过OPC方式连接PLC,用这种方式连PLC不用考虑什么种类PLC,只要OPC服务器里有的PLC都可以连。_c#opc通信

Hyper-V内的虚拟机复制粘贴_win10 hyper-v ubuntu18.04 文件拷贝-程序员宅基地

文章浏览阅读1.6w次,点赞3次,收藏10次。实践环境物理机:Windows10教育版,操作系统版本 17763.914虚拟机:Ubuntu18.04.3桌面版在Hyper-V中的刚安装好Ubuntu虚拟机之后,会发现鼠标滑动很不顺畅,也不能向虚拟机中拖拽文件或者复制内容。在VMware中,可以通过安装VMware tools来使物理机和虚拟机之间达到更好的交互。在Hyper-V中,也有这样的工具。这款工具可以完成更好的鼠标交互,我的..._win10 hyper-v ubuntu18.04 文件拷贝

java静态变量初始化多线程,持续更新中_类初始化一个静态属性 为线程池-程序员宅基地

文章浏览阅读156次。前言互联网时代,瞬息万变。一个小小的走错,就有可能落后于别人。我们没办法去预测任何行业、任何职业未来十年会怎么样,因为未来谁都不能确定。只能说只要有互联网存在,程序员依然是个高薪热门行业。只要跟随着时代的脚步,学习新的知识。程序员是不可能会消失的,或者说不可能会没钱赚的。我们经常可以听到很多人说,程序员是一个吃青春饭的行当。因为大多数人认为这是一个需要高强度脑力劳动的工种,而30岁、40岁,甚至50岁的程序员身体机能逐渐弱化,家庭琐事缠身,已经不能再进行这样高强度的工作了。那么,这样的说法是对的么?_类初始化一个静态属性 为线程池

idea 配置maven,其实不用单独下载Maven的。以及设置新项目配置,省略每次创建新项目都要配置一次Maven_安装idea后是不是不需要安装maven了?-程序员宅基地

文章浏览阅读1w次,点赞13次,收藏43次。说来也是惭愧,一直以来,在装环境的时候都会从官网下载Maven。然后再在idea里配置Maven。以为从官网下载的Maven是必须的步骤,直到今天才得知,idea有捆绑的 Maven 我们只需要搞一个配置文件就行了无需再官网下载Maven包以后再在新电脑装环境的时候,只需要下载idea ,网上找一个Maven的配置文件 放到 默认的 包下面就可以了!也省得每次创建项目都要重新配一次Maven了。如果不想每次新建项目都要重新配置Maven,一种方法就是使用默认的配置,另一种方法就是配置 .._安装idea后是不是不需要安装maven了?

奶爸奶妈必看给宝宝摄影大全-程序员宅基地

文章浏览阅读45次。家是我们一生中最重要的地方,小时候,我们在这里哭、在这里笑、在这里学习走路,在这里有我们最真实的时光,用相机把它记下吧。  很多家庭在拍摄孩子时有一个看法,认为儿童摄影团购必须是在风景秀丽的户外,即便是室内那也是像大酒店一样...

构建Docker镜像指南,含实战案例_rocker/r-base镜像-程序员宅基地

文章浏览阅读429次。Dockerfile介绍Dockerfile是构建镜像的指令文件,由一组指令组成,文件中每条指令对应linux中一条命令,在执行构建Docker镜像时,将读取Dockerfile中的指令,根据指令来操作生成指定Docker镜像。Dockerfile结构:主要由基础镜像信息、维护者信息、镜像操作指令、容器启动时执行指令。每行支持一条指令,每条指令可以携带多个参数。注释可以使用#开头。指令说明FROM 镜像 : 指定新的镜像所基于的镜像MAINTAINER 名字 : 说明新镜像的维护(制作)人,留下_rocker/r-base镜像

随便推点

毕设基于微信小程序的小区管理系统的设计ssm毕业设计_ssm基于微信小程序的公寓生活管理系统-程序员宅基地

文章浏览阅读223次。该系统将提供便捷的信息发布、物业报修、社区互动等功能,为小区居民提供更加便利、高效的服务。引言: 随着城市化进程的加速,小区管理成为一个日益重要的任务。因此,设计一个基于微信小程序的小区管理系统成为了一项具有挑战性和重要性的毕设课题。本文将介绍该小区管理系统的设计思路和功能,以期为小区提供更便捷、高效的管理手段。四、总结与展望: 通过本次毕设项目,我们实现了一个基于微信小程序的小区管理系统,为小区居民提供了更加便捷、高效的服务。通过该系统的设计与实现,能够提高小区管理水平,提供更好的居住环境和服务。_ssm基于微信小程序的公寓生活管理系统

如何正确的使用Ubuntu以及安装常用的渗透工具集.-程序员宅基地

文章浏览阅读635次。文章来源i春秋入坑Ubuntu半年多了记得一开始学的时候基本一星期重装三四次=-= 尴尬了 觉得自己差不多可以的时候 就吧Windows10干掉了 c盘装Ubuntu 专心学习. 这里主要来说一下使用Ubuntu的正确姿势Ubuntu(友帮拓、优般图、乌班图)是一个以桌面应用为主的开源GNU/Linux操作系统,Ubuntu 是基于DebianGNU/Linux,支..._ubuntu安装攻击工具包

JNI参数传递引用_jni引用byte[]-程序员宅基地

文章浏览阅读335次。需求:C++中将BYTE型数组传递给Java中,考虑到内存释放问题,未采用通过返回值进行数据传递。public class demoClass{public native boolean getData(byte[] tempData);}JNIEXPORT jboolean JNICALL Java_com_core_getData(JNIEnv *env, jobject thisObj, jbyteArray tempData){ //resultsize为s..._jni引用byte[]

三维重建工具——pclpy教程之点云分割_pclpy.pcl.pointcloud.pointxyzi转为numpy-程序员宅基地

文章浏览阅读2.1k次,点赞5次,收藏30次。本教程代码开源:GitHub 欢迎star文章目录一、平面模型分割1. 代码2. 说明3. 运行二、圆柱模型分割1. 代码2. 说明3. 运行三、欧几里得聚类提取1. 代码2. 说明3. 运行四、区域生长分割1. 代码2. 说明3. 运行五、基于最小切割的分割1. 代码2. 说明3. 运行六、使用 ProgressiveMorphologicalFilter 分割地面1. 代码2. 说明3. 运行一、平面模型分割在本教程中,我们将学习如何对一组点进行简单的平面分割,即找到支持平面模型的点云中的所有._pclpy.pcl.pointcloud.pointxyzi转为numpy

以NFS启动方式构建arm-linux仿真运行环境-程序员宅基地

文章浏览阅读141次。一 其实在 skyeye 上移植 arm-linux 并非难事,网上也有不少资料, 只是大都遗漏细节, 以致细微之处卡壳,所以本文力求详实清析, 希望能对大家有点用处。本文旨在将 arm-linux 在 skyeye 上搭建起来,并在 arm-linux 上能成功 mount NFS 为目标, 最终我们能在 arm-linux 里运行我们自己的应用程序. 二 安装 Sky..._nfs启动 arm

攻防世界 Pwn 进阶 第二页_pwn snprintf-程序员宅基地

文章浏览阅读598次,点赞2次,收藏5次。00为了形成一个体系,想将前面学过的一些东西都拉来放在一起总结总结,方便学习,方便记忆。攻防世界 Pwn 新手攻防世界 Pwn 进阶 第一页01 4-ReeHY-main-100超详细的wp1超详细的wp203 format2栈迁移的两种作用之一:栈溢出太小,进行栈迁移从而能够写入更多shellcode,进行更多操作。栈迁移一篇搞定有个陌生的函数。C 库函数 void *memcpy(void *str1, const void *str2, size_t n) 从存储区 str2 _pwn snprintf

推荐文章

热门文章

相关标签