2017年2月21日 星期二

Microsoft Cognitive Face API

Ref : https://www.microsoft.com/cognitive-services/en-us/face-api


Face Detection








ry this now by uploading a local image, or providing an image URL. We don’t keep your images for this demo unless you give us permission.





result : 

Response 200

A successful call returns an array of face entries ranked by face rectangle size in descending order. An empty response indicates no faces detected. A face entry may contain the following values depending on input parameters:
FieldsTypeDescription
faceIdStringUnique faceId of the detected face, created by detection API and it will expire in 24 hours after detection call. To return this, it requires "returnFaceId" parameter to be true.
faceRectangleObjectA rectangle area for the face location on image.
faceLandmarksObjectAn array of 27-point face landmarks pointing to the important positions of face components. To return this, it requires "returnFaceLandmarks" parameter to be true.
faceAttributesObjectFace Attributes:
  • age: an age number in years.
  • gender: male or female.
  • smile: smile intensity, a number between [0,1]
  • facialHair: consists of lengths of three facial hair areas: moustache, beard and sideburns.
  • headPose: 3-D roll/yew/pitch angles for face direction. Pitch value is a reserved field and will always return 0.
  • glasses: glasses type. Possible values are 'noGlasses', 'readingGlasses', 'sunglasses', 'swimmingGoggles'.
[
    {
        "faceId": "c5c24a82-6845-4031-9d5d-978df9175426",
        "faceRectangle": {
            "width": 78,
            "height": 78,
            "left": 394,
            "top": 54
        },
        "faceLandmarks": {
            "pupilLeft": {
                "x": 412.7,
                "y": 78.4 
            },
            "pupilRight": {
                "x": 446.8,
                "y": 74.2 
            },
            "noseTip": {
                "x": 437.7,
                "y": 92.4 
            },
            "mouthLeft": {
                "x": 417.8,
                "y": 114.4 
            },
            "mouthRight": {
                "x": 451.3,
                "y": 109.3 
            },
            "eyebrowLeftOuter": {
                "x": 397.9,
                "y": 78.5 
            },
            "eyebrowLeftInner": {
                "x": 425.4,
                "y": 70.5 
            },
            "eyeLeftOuter": {
                "x": 406.7,
                "y": 80.6 
            },
            "eyeLeftTop": {
                "x": 412.2,
                "y": 76.2 
            },
            "eyeLeftBottom": {
                "x": 413.0,
                "y": 80.1 
            },
            "eyeLeftInner": {
                "x": 418.9,
                "y": 78.0 
            },
            "eyebrowRightInner": {
                "x": 4.8,
                "y": 69.7 
            },
            "eyebrowRightOuter": {
                "x": 5.5,
                "y": 68.5 
            },
            "eyeRightInner": {
                "x": 441.5,
                "y": 75.0 
            },
            "eyeRightTop": {
                "x": 446.4,
                "y": 71.7 
            },
            "eyeRightBottom": {
                "x": 447.0,
                "y": 75.3 
            },
            "eyeRightOuter": {
                "x": 451.7,
                "y": 73.4 
            },
            "noseRootLeft": {
                "x": 428.0,
                "y": 77.1 
            },
            "noseRootRight": {
                "x": 435.8,
                "y": 75.6 
            },
            "noseLeftAlarTop": {
                "x": 428.3,
                "y": 89.7 
            },
            "noseRightAlarTop": {
                "x": 442.2,
                "y": 87.0 
            },
            "noseLeftAlarOutTip": {
                "x": 424.3,
                "y": 96.4 
            },
            "noseRightAlarOutTip": {
                "x": 446.6,
                "y": 92.5 
            },
            "upperLipTop": {
                "x": 437.6,
                "y": 105.9 
            },
            "upperLipBottom": {
                "x": 437.6,
                "y": 108.2 
            },
            "underLipTop": {
                "x": 436.8,
                "y": 111.4 
            },
            "underLipBottom": {
                "x": 437.3,
                "y": 114.5 
            }
        },
        "faceAttributes": {
            "age": 71.0,
            "gender": "male",
            "smile": 0.88,
            "facialHair": {
                "mustache": 0.8,
                "beard": 0.1,
                "sideburns": 0.02
                }
            },
            "glasses": "sunglasses",
            "headPose": {
                "roll": 2.1,
                "yaw": 3,
                "pitch": 0
            }
        }
    }
]

Response 400

Error code and message returned in JSON:
Error CodeError Message Description
BadArgumentJSON parsing error. Bad or unrecognizable request JSON body.
BadArgumentInvalid returnFaceAttributes. Supported values are: age, gender, headPose, smile, facialHair, glasses in a comma-separated format.
InvalidURLInvalid image format or URL. Supported formats include JPEG, PNG, GIF(the first frame) and BMP.
InvalidURLFailed to download image from the specified URL. Remote server error returned.
InvalidImageDecoding error, image format unsupported.
InvalidImageSizeImage size is too small or too big. The valid image file size should be larger than or equal to 1KB but no larger than 4MB.
{
    "error":{
        "code":"BadArgument",
        "message":"Request body is invalid." 
    }
}

Response 401

Error code and message returned in JSON:
Error CodeError Message Description
UnspecifiedInvalid subscription Key or user/plan is blocked.
{
    "error":{
        "code": "Unspecified",
        "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key." 
    }
}

Response 403

{
    "error":{
        "statusCode": 403,
        "message": "Out of call volume quota. Quota will be replenished in 2.12 days." 
    }
}

Response 408

Operation exceeds maximum execution time.
{
    "error":{
        "code":"OperationTimeOut",
        "message":"Request Timeout." 
    }
}

Response 415

Unsupported media type error. Content-Type is not in the allowed types:
  1. For an image URL, Content-Type should be application/json
  2. For a local image, Content-Type should be application/octet-stream
{
    "error":{
        "code":"BadArgument",
        "message":"Invalid Media Type" 
    }
}

Response 429

{
    "error":{
       "statusCode": 429,
        "message": "Rate limit is exceeded. Try again in 26 seconds." 
    }
}
php sample:
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://westus.api.cognitive.microsoft.com/face/v1.0/detect');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'returnFaceId' => 'true',
    'returnFaceLandmarks' => 'false',
    'returnFaceAttributes' => '{string}',
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");
/*
{
    "url":"http://example.com/1.jpg"
}
*/

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>




















2017年2月20日 星期一

網站資訊安全


第一步先設定  linode 的os  , 建議選  centos  6.5版


使用putty連線進去後...

一開始先打

yum update

yum update 這是系統更新指令~ 一般建議做系統之前把OS 更新到最新!!
這樣可以減少系統建立過成新舊版本相依性的問題


接下來重開機

reboot 重開機指令~ 更新完成後雖然不強制重開~ 但習慣還是重開一次讓OS 重新讀取~
KVM 虛擬化技術的 reboot 速度比較慢~ XD 但優點是通常不會超賣...


===================================================================

今天的重點是SSL

使用  vestacp  的這一版....SSL 有bug


因為 VestaCP Let 取得SSL 似乎是1月份更新後的BUG
還沒修正~
目前要用SSL 免費的除了 Let 這個方法外~
還有一個 用 Cloudflare 的 SSL
我簡稱他CF
CF 如果有燒為研究~ 都知道他是知名的網站快取服務~
XD 之前很多網站被惡意DDOS 都是 CF 幫忙檔下來的...
我等等要做的事情~ 就是把 Godaddy 的 DNS 設定轉丟到 CF 作代管~
用CF 來管理你的DNS ~ 這樣就可以使用 CF 的免費SSL ~
CF 的DNS 代管 基本上我也覺得比 Godaddy 的好用~
重點免費版就附帶DDOS 防護~ 還滿推薦使用的~ 以上....XD


為了減少開發時間....我們改用其他的服務...  


cloudflare


Ref : https://sofree.cc/cloudflare-free-ssl/


首先到他的官網去註冊一個帳號...

選免費的...

設定一下 DNS....
































重點是這個DNS

Cloudflare Nameservers

For your records, here are the Cloudflare nameservers you've been assigned.
TypeValue
NScruz.ns.cloudflare.com
NSmarty.ns.cloudflare.com



由於我的網址是跟godaddy 買的...

所以要godaddy去改設定


進到產品管理頁面

DNS 管理...   點選變更....

改成上面的那兩個伺服器


上次更新 2017/2/20 下午3:33
使用自訂名稱伺服器  
網域名稱伺服器
cruz.ns.cloudflare.com
marty.ns.cloudflare.com

接下來就是CF 得設定




===============================================================


由於vestacp 安裝好後...

account 是 root

port :22

這樣很危險

我們要修改一下




1 修改 SSH Root 登入權限~
http://mepopedia.com/forum/read.php?135,5748
2 增加 Sudo 權限用戶
2-1 建立使用者
http://linux.vbird.org/linux_basic/0410accountmanager/0410accountmanager-fc4.php#useradd

useradd jacky_chi    (jacky_chi 是你的使用者名字)
passwd  密碼




重開服務
service sshd restart


2-2 加入Sudo 清單
http://ithelp.ithome.com.tw/articles/10053821


visudo

找到這一行
root ALL=(ALL) ALL
在她下面加入你得帳號

ex:

jacky ALL=(ALL) ALL


然後重開服務
service sshd restart

3. 修改 SSH Port 和關掉root 的帳戶登入功能
回到前面修改 SSH root 登入的設定檔
要特別注意~ 這邊需要連帶修改 IPTABLE 的設定

Ref : http://mepopedia.com/forum/read.php?135,5748

1. 找到檔案 /etc/ssh/sshd_config 

2. 修改其中的 

#PermitRootLogin yes 

改為 

PermitRootLogin no (注意開頭不要有井字號 #) 

然後改port 的地方在

#port 22

把# 拿掉..   把22改成你要的port num

接下來去修改   vestacp 的防火牆設定
























按下編輯....修改成你的port number