Skip to content

Commit db21322

Browse files
committed
image-process-opencv-lambda
1 parent e7daa24 commit db21322

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
-*- coding: utf-8 -*-
3+
========================
4+
AWS Lambda
5+
========================
6+
Contributor: Chirag Rathod (Srce Cde)
7+
========================
8+
"""
9+
import cv2
10+
import numpy as np
11+
import boto3
12+
13+
14+
def lambda_handler(event, context):
15+
s3 = boto3.client("s3")
16+
bucket_name = "bucket_name"
17+
file_obj = s3.get_object(Bucket=bucket_name, Key="obj_scene.jpeg")
18+
file_content = file_obj["Body"].read()
19+
20+
np_array = np.fromstring(file_content, np.uint8)
21+
image_np = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
22+
23+
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
24+
cv2.imwrite("/tmp/gray_obj.jpg", gray)
25+
26+
s3.put_object(Bucket=bucket_name, Key="grayscale.jpg", Body=open("/tmp/gray_obj.jpg", "rb").read())
27+
28+
return "Thanks"

0 commit comments

Comments
 (0)