Skip to main content

Amazon Rekognition

Amazon Rekognition คือบริการวิเคราะห์รูปภาพและวิดีโอด้วย AI ที่ไม่จำเป็นต้องมีความรู้ด้าน Machine Learning ล่วงหน้า บริการนี้ใช้โมเดล Deep Learning ที่ผ่านการฝึกมาจากรูปภาพนับพันล้านภาพ ทำให้สามารถตรวจจับวัตถุ วิเคราะห์ใบหน้า อ่านข้อความในรูปภาพ และกรองเนื้อหาที่ไม่เหมาะสมได้อย่างแม่นยำผ่าน API เพียงไม่กี่บรรทัด

Rekognition รองรับทั้งการวิเคราะห์รูปภาพ (Image Analysis) และวิดีโอ (Video Analysis) ทั้งแบบ stored video และ streaming video แบบ real-time นอกจากนี้ยังมี Custom Labels ที่ช่วยให้สามารถฝึกโมเดลด้วยรูปภาพของตัวเองได้ เพื่อตรวจจับวัตถุหรือสิ่งที่เฉพาะเจาะจงกับธุรกิจ

AWS Docs: https://docs.aws.amazon.com/rekognition/latest/dg/what-is.html

สถาปัตยกรรม


ฟีเจอร์หลัก

Object and Scene Detection

ตรวจจับวัตถุ สัตว์ สถานที่ กิจกรรม และฉากต่างๆ ในรูปภาพ พร้อม confidence score และ bounding box ระบบสามารถจำแนกได้กว่า 1,000 หมวดหมู่ เช่น รถยนต์ อาหาร เครื่องแต่งกาย สัตว์เลี้ยง สถานที่ท่องเที่ยว และอื่นๆ อีกมาก

Facial Analysis

วิเคราะห์คุณลักษณะของใบหน้าที่ตรวจพบในรูปภาพ ประกอบด้วย:

  • Emotions ระบุอารมณ์ 7 ประเภท ได้แก่ HAPPY, SAD, ANGRY, SURPRISED, DISGUSTED, CONFUSED, CALM
  • Age Range ประมาณอายุด้วยช่วงค่า เช่น 25-35 ปี
  • Gender ระบุเพศ (Male/Female) พร้อม confidence score
  • Facial Attributes เช่น แว่นตา, หนวดเครา, รอยยิ้ม, ตาเปิด/ปิด, การใส่แมสก์

เปรียบเทียบใบหน้าสองรูปว่าเป็นบุคคลเดียวกันหรือไม่ (Face Comparison) และค้นหาใบหน้าจาก collection ที่สร้างไว้ล่วงหน้า (Face Search) ด้วย confidence threshold ที่กำหนดได้ เหมาะสำหรับระบบ KYC และ access control

Celebrity Recognition

ระบุตัวตนบุคคลสาธารณะและคนดังจากฐานข้อมูลนับล้านคน พร้อม URL ไปยังข้อมูลเพิ่มเติม เหมาะสำหรับ media monitoring และ content tagging

Text Detection (OCR)

ตรวจจับและอ่านข้อความที่ปรากฏในรูปภาพ ทั้งที่พิมพ์และเขียนด้วยมือ รองรับข้อความในฉากธรรมชาติ เช่น ป้ายโฆษณา ป้ายทะเบียน เมนูร้านอาหาร และป้ายถนน

Content Moderation

ตรวจจับเนื้อหาที่ไม่เหมาะสมและเนื้อหาผู้ใหญ่ในรูปภาพและวิดีโอ จำแนกออกเป็นหลายหมวดหมู่พร้อม confidence score ช่วยให้แพลตฟอร์มโซเชียลมีเดียและ marketplace กรองเนื้อหาได้โดยอัตโนมัติ รองรับ human review workflow ผ่าน Amazon Augmented AI (A2I)

PPE Detection

ตรวจจับอุปกรณ์ป้องกันส่วนบุคคล (Personal Protective Equipment) เช่น หมวกนิรภัย แว่นตา หน้ากาก ถุงมือ และเสื้อกั๊กสะท้อนแสง เหมาะสำหรับ workplace safety monitoring ในโรงงานและไซต์ก่อสร้าง

Custom Labels

ฝึกโมเดลตรวจจับวัตถุหรือ scene เฉพาะทางด้วยรูปภาพของตัวเองเพียงไม่กี่สิบถึงไม่กี่ร้อยภาพ ใช้เทคนิค transfer learning ไม่ต้องมีความรู้ ML ลึกๆ เหมาะสำหรับ quality inspection, product recognition, brand logo detection

Video Analysis (Stored Video)

วิเคราะห์วิดีโอที่เก็บใน S3 แบบ asynchronous สำหรับ object detection, activity detection, face search, celebrity recognition และ content moderation ผ่าน API เดียวกัน

Video Analysis (Streaming)

วิเคราะห์ video stream แบบ real-time ผ่าน Kinesis Video Streams สำหรับ use cases เช่น live surveillance, retail analytics และ smart home

Face Liveness (Anti-Spoofing)

ตรวจสอบว่าใบหน้าที่อยู่หน้ากล้องเป็นคนจริงๆ หรือภาพถ่าย/วิดีโอ ด้วยการให้ผู้ใช้แสดง action แบบ random เหมาะสำหรับ KYC (Know Your Customer) และการยืนยันตัวตนออนไลน์ เช่น การเปิดบัญชีธนาคาร


การติดตั้งและการตั้งค่า

1. เปิดใช้งานผ่าน AWS Console

  1. เข้า AWS Console และค้นหา "Amazon Rekognition"
  2. บริการพร้อมใช้งานทันที ไม่ต้อง provision resources
  3. สำหรับ Custom Labels ให้กด "Use Amazon Rekognition" และสร้าง Project

2. ติดตั้ง boto3

pip install boto3 Pillow

3. IAM Permissions ที่จำเป็น

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rekognition:DetectLabels",
"rekognition:DetectFaces",
"rekognition:CompareFaces",
"rekognition:SearchFacesByImage",
"rekognition:DetectText",
"rekognition:DetectModerationLabels",
"rekognition:DetectProtectiveEquipment",
"rekognition:IndexFaces",
"rekognition:CreateCollection",
"rekognition:StartLabelDetection",
"rekognition:GetLabelDetection",
"rekognition:DetectCustomLabels",
"rekognition:DetectFaceLiveness"
],
"Resource": "*"
}
]
}

4. ตัวอย่างการตั้งค่า boto3

import boto3

rekognition = boto3.client(
service_name='rekognition',
region_name='ap-southeast-1'
)

วิธีใช้งาน

Object and Scene Detection

import boto3

rekognition = boto3.client('rekognition', region_name='ap-southeast-1')

# วิเคราะห์รูปภาพจาก S3
response = rekognition.detect_labels(
Image={
'S3Object': {
'Bucket': 'my-images-bucket',
'Name': 'product-photo.jpg'
}
},
MaxLabels=20,
MinConfidence=80
)

for label in response['Labels']:
print(f"Label: {label['Name']} | Confidence: {label['Confidence']:.1f}%")

# แสดง bounding boxes ถ้ามี
if label.get('Instances'):
for instance in label['Instances']:
box = instance['BoundingBox']
print(f" BoundingBox: top={box['Top']:.2f}, left={box['Left']:.2f}")

Face Analysis

# วิเคราะห์ใบหน้าในรูปภาพ
response = rekognition.detect_faces(
Image={
'S3Object': {'Bucket': 'my-bucket', 'Name': 'group-photo.jpg'}
},
Attributes=['ALL']
)

for face in response['FaceDetails']:
print(f"Age Range: {face['AgeRange']['Low']}-{face['AgeRange']['High']} ปี")
print(f"Gender: {face['Gender']['Value']} ({face['Gender']['Confidence']:.1f}%)")

# แสดง emotions
emotions = sorted(face['Emotions'], key=lambda x: x['Confidence'], reverse=True)
print(f"Top Emotion: {emotions[0]['Type']} ({emotions[0]['Confidence']:.1f}%)")

# Face attributes
print(f"Smile: {face['Smile']['Value']} ({face['Smile']['Confidence']:.1f}%)")
print(f"Eyeglasses: {face['Eyeglasses']['Value']}")
print("---")

Face Search (KYC System)

# สร้าง face collection
rekognition.create_collection(CollectionId='employees-collection')

# เพิ่มใบหน้าพนักงานเข้า collection
rekognition.index_faces(
CollectionId='employees-collection',
Image={'S3Object': {'Bucket': 'hr-photos', 'Name': 'employee_001.jpg'}},
ExternalImageId='EMP001',
DetectionAttributes=['ALL']
)

# ค้นหาใบหน้าจากรูปภาพใหม่
response = rekognition.search_faces_by_image(
CollectionId='employees-collection',
Image={'S3Object': {'Bucket': 'access-camera', 'Name': 'captured_face.jpg'}},
MaxFaces=1,
FaceMatchThreshold=95
)

if response['FaceMatches']:
match = response['FaceMatches'][0]
print(f"Found: {match['Face']['ExternalImageId']}")
print(f"Similarity: {match['Similarity']:.1f}%")
else:
print("No match found - Access Denied")

Content Moderation

# ตรวจสอบเนื้อหาที่ไม่เหมาะสม
response = rekognition.detect_moderation_labels(
Image={'S3Object': {'Bucket': 'user-uploads', 'Name': 'uploaded_image.jpg'}},
MinConfidence=75
)

if response['ModerationLabels']:
print("Content flagged:")
for label in response['ModerationLabels']:
print(f" {label['Name']} ({label['ParentName']}): {label['Confidence']:.1f}%")
# ลบรูปภาพหรือส่งให้ human reviewer
else:
print("Content is appropriate")

Video Analysis

# เริ่ม async video analysis
response = rekognition.start_label_detection(
Video={
'S3Object': {'Bucket': 'video-bucket', 'Name': 'store-footage.mp4'}
},
MinConfidence=80,
NotificationChannel={
'SNSTopicArn': 'arn:aws:sns:ap-southeast-1:123456789:rekognition-complete',
'RoleArn': 'arn:aws:iam::123456789:role/RekognitionRole'
}
)

job_id = response['JobId']
print(f"Video analysis started: {job_id}")

# ดึงผลลัพธ์
result = rekognition.get_label_detection(
JobId=job_id,
SortBy='TIMESTAMP'
)

for label in result['Labels']:
timestamp_ms = label['Timestamp']
print(f"[{timestamp_ms/1000:.1f}s] {label['Label']['Name']}: {label['Label']['Confidence']:.1f}%")

Custom Labels

# ใช้ Custom Labels model ที่ฝึกแล้ว
response = rekognition.detect_custom_labels(
ProjectVersionArn='arn:aws:rekognition:ap-southeast-1:123:project/defect-detector/version/v1/...',
Image={'S3Object': {'Bucket': 'factory-images', 'Name': 'product_scan.jpg'}},
MinConfidence=90
)

for label in response['CustomLabels']:
print(f"Defect: {label['Name']} | Confidence: {label['Confidence']:.1f}%")
if label.get('Geometry'):
box = label['Geometry']['BoundingBox']
print(f" Location: top={box['Top']:.2f}, left={box['Left']:.2f}")

ราคา (ประมาณการในบาท)

อัตราแลกเปลี่ยน: 1 USD = 35 บาท

ฟีเจอร์ราคา (USD)ราคา (บาท)
Image Analysis (Object, Scene, Face)$0.001/image0.035 บาท/รูป
Face Search (IndexFaces, SearchFaces)$0.001/image0.035 บาท/รูป
Celebrity Recognition$0.001/image0.035 บาท/รูป
Text Detection$0.001/image0.035 บาท/รูป
Content Moderation$0.001/image0.035 บาท/รูป
PPE Detection$0.001/image0.035 บาท/รูป
Video Analysis (Stored)$0.10/minute3.50 บาท/นาที
Video Streaming Analysis$0.10/minute3.50 บาท/นาที
Custom Labels Training$1.00/hour35 บาท/ชม.
Custom Labels Inference$4.00/hour140 บาท/ชม.
Face Liveness$0.01/session0.35 บาท/ครั้ง

Free Tier: 5,000 รูปภาพ/เดือน และ 1,000 นาทีวิดีโอ/เดือน ใน 12 เดือนแรก

ตัวอย่างการคำนวณ:

  • วิเคราะห์รูปสินค้า 1,000,000 รูป = $1,000 (~35,000 บาท)
  • วิดีโอ CCTV 24 ชม./วัน = 1,440 นาที × $0.10 = $144/วัน (~5,040 บาท/วัน)
  • Custom Labels inference 8 ชม./วัน = 8 × $4 = $32/วัน (~1,120 บาท/วัน)

เหมาะสำหรับ

  • ระบบ KYC และ eKYC ของธนาคาร บริษัทประกัน และ Fintech ที่ต้องการยืนยันตัวตนออนไลน์
  • ระบบรักษาความปลอดภัย สำหรับ access control, surveillance และตรวจจับบุคคลต้องสงสัย
  • แพลตฟอร์ม Social Media และ UGC ที่ต้องการ auto-moderate content ไม่เหมาะสม
  • Retail และ E-Commerce สำหรับ visual search, product tagging และ shelf monitoring
  • โรงงานและการผลิต สำหรับ quality control และ defect detection ด้วย Custom Labels
  • สื่อและ Entertainment สำหรับ content tagging, celebrity recognition และ subtitle generation

ใช้ร่วมกับ AWS Services

AWS Serviceการผสานรวม
Amazon S3เก็บรูปภาพและวิดีโอที่ต้องการวิเคราะห์
AWS Lambdaประมวลผล Rekognition เมื่อมีไฟล์ใหม่ใน S3
Amazon Kinesis Video Streamsส่ง video stream สำหรับ real-time analysis
Amazon SNSรับ notification เมื่อ video analysis เสร็จ
Amazon DynamoDBเก็บ face collection metadata และ analysis results
Amazon Augmented AI (A2I)Human review workflow สำหรับ content moderation
AWS Step Functionsสร้าง image processing pipeline
Amazon CloudWatchmonitor API usage และ model performance

Use Case ตัวอย่าง

1. ระบบ eKYC สำหรับธนาคาร

ธนาคารดิจิทัลใช้ Rekognition Face Liveness และ Face Comparison สำหรับกระบวนการเปิดบัญชีออนไลน์ ลูกค้าถ่ายรูปบัตรประชาชนและทำ liveness check ผ่านแอปมือถือ ระบบใช้ Textract อ่านข้อมูลจากบัตรประชาชน จากนั้น Rekognition เปรียบเทียบใบหน้าจากบัตรกับภาพถ่าย real-time พร้อมตรวจสอบ liveness เพื่อป้องกันการปลอมแปลง กระบวนการ KYC ที่เคยใช้เวลา 3-5 วันลดเหลือ 5 นาที และลดต้นทุนการยืนยันตัวตนลง 80%

2. ระบบ Quality Control โรงงาน

โรงงานผลิตชิ้นส่วนอิเล็กทรอนิกส์ใช้ Rekognition Custom Labels ตรวจจับ defects บนสายการผลิต ฝึกโมเดลด้วยรูปภาพชิ้นส่วนที่ดี/เสีย 500 รูป กล้อง high-speed ถ่ายรูปสินค้าทุกชิ้นและส่งเข้า Lambda สำหรับวิเคราะห์ real-time ระบบตรวจจับ defects ได้ 99.2% และ reject ชิ้นส่วนที่เสียก่อนออกจากสายการผลิต ลด defect rate ที่ถึงมือลูกค้าจาก 0.3% เหลือ 0.02%

3. ระบบ Content Moderation แพลตฟอร์ม Social

แพลตฟอร์มโซเชียลมีเดียรับ user-generated content กว่า 2 ล้านรูปต่อวัน ระบบ Lambda trigger ทำงานทันทีเมื่อมีการอัปโหลด โดยเรียก Rekognition detect_moderation_labels เพื่อตรวจสอบเนื้อหาไม่เหมาะสม รูปภาพที่มี confidence สูงจะถูก auto-reject ส่วนรูปที่ confidence ปานกลางจะถูกส่งไปยัง human reviewer ผ่าน Amazon A2I ระบบลดเวลา review เนื้อหาลง 95% และ human moderator สามารถ focus เฉพาะ borderline cases