Ashrafb commited on
Commit
ee4c1f6
·
verified ·
1 Parent(s): 8c18f47

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -5
main.py CHANGED
@@ -191,14 +191,17 @@ async def process_image(file: UploadFile = File(...), top: int = Form(...), bott
191
  return {"error": "Model not loaded."}
192
 
193
  # Save the uploaded image locally with its original filename
194
- with open(file.filename, "wb") as buffer:
195
  shutil.copyfileobj(file.file, buffer)
196
 
 
 
 
 
 
 
197
  # Process the uploaded image
198
- # Load the image and convert it from BGR to RGB
199
- frame = cv2.imread(file.filename)
200
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
201
- aligned_face, instyle, message = model.detect_and_align_image(frame, top, bottom, left, right)
202
  processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1')
203
 
204
  # Convert processed image to bytes
 
191
  return {"error": "Model not loaded."}
192
 
193
  # Save the uploaded image locally with its original filename
194
+ with open("uploaded_image.jpg", "wb") as buffer:
195
  shutil.copyfileobj(file.file, buffer)
196
 
197
+ # Read the saved image using OpenCV
198
+ frame = cv2.imread("uploaded_image.jpg")
199
+
200
+ # Convert the image from BGR to RGB
201
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
202
+
203
  # Process the uploaded image
204
+ aligned_face, instyle, message = model.detect_and_align_image("uploaded_image.jpg", top, bottom, left, right)
 
 
 
205
  processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1')
206
 
207
  # Convert processed image to bytes