How to crop face from a photo using cv2 in python

0 votes

Hi Guys,

I am working in a project where I need to crop face from a photo for Machine Learning. Can anyone tell me, how can I do that in python?

Thank You

Apr 9, 2020 in Python by akhtar
• 38,210 points
201 views

1 answer to this question.

0 votes

Hi@akhtar,

You can do this task using cv2 module in python. Use the below given code.

import cv2
photo = cv2.imread('img1.png')
photo1 = photo[140:500, 780:1050] 
cv2.imshow('My Photo', photo1)
cv2.waitKey()
cv2.destroyAllWindows()

Before running this code, make sure you change dimensions according to your need.

Hope this will work.

answered Apr 9, 2020 by MD
• 95,300 points

Related Questions In Python

0 votes
1 answer

Shortest path from source to and from a negative cycle using Bellman Ford in Python

class NegativeWeightFinder: def __init__(self, graph: nx.Graph): ...READ MORE

answered Nov 13, 2018 in Python by Nymeria
• 3,520 points
683 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,480 points
72,068 views
0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,780 points
633 views
0 votes
0 answers

How to implement multiple try codes in a single block using Python?

Hi all, As per the title, I am ...READ MORE

Jan 14, 2019 in Python by Anirudh
• 2,080 points
174 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,366 views
0 votes
0 answers
0 votes
1 answer

video streaming using cv2 module in python.

Hi@akhtar, Yes, you can use cv2 module for ...READ MORE

answered Apr 15, 2020 in Python by MD
• 95,300 points
229 views
0 votes
1 answer

How to read photo using cv2 module in python?

Hi@akhtar, Yes, you can read your image in ...READ MORE

answered Apr 9, 2020 in Python by MD
• 95,300 points
146 views
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,300 points
243 views