X Tutup
The Wayback Machine - https://web.archive.org/web/20250521081248/https://github.com/TheAlgorithms/Python/pull/4669
Skip to content

Added mediapipeDetection file for person detection (Face, hands, pose detection) #4669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

ShaswatPanda
Copy link

@ShaswatPanda ShaswatPanda commented Aug 25, 2021

Face, Hand, and Pose Detection Using Mediapipe and OpenCV

Fixes Issue #4668

Functionalities include face, hand, and pose detection. This file focuses on pose detection.

Functionalities:

  • Pose detection using pose process
  • Face, hand, and pose detection using holistic process
  • Angle detection in all major joints of the detected body
  • Support for angle detection in all three planes added (XY[Default], YZ, and XZ)
  • Support for graphing included.
  • Graphs can be produced at the end of the runtime session or can be produced dynamically and in real-time
  • Support for logging added.
  • Local videos can also be processed in addition to real-time video feed from a webcam
  • Frames per second (FPS) counter shown to measure performance

Improvements:

  • Added an algorithm
  • Added/improved functionality

Screenshots:

image
Screenshot (244)
Screenshot (250)
Screenshot (247)
Screenshot (245)

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • ThisPR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Functionalities include face, hand, and pose detection. This file focuses on pose detection.
@ghost ghost added awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Aug 25, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

# FEED CAPTURE
cap = cv2.VideoCapture(0) # Webcam feed

pTime = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: pTime


make_1080p()

def make_720p():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: make_720p. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_720p

cap.set(3, 1280)
cap.set(4, 720)

def make_480p():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: make_480p. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_480p


#make_480p()

def change_res(width, height):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: change_res. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function change_res

Please provide type hint for the parameter: width

Please provide type hint for the parameter: height

backStage1 = "Crooked"
backStage2 = "Crooked"
backColor = red
backStage = "Crooked"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backStage

# Sitting-Standing condition

if backStage=="Crooked" and stage3=="Folded" and stage4=="Folded":
sittingStage = "Sitting"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: sittingStage

if backStage=="Crooked" and stage3=="Folded" and stage4=="Folded":
sittingStage = "Sitting"
if backStage=="Straight" and stage3=="Stretched" and stage4=="Stretched" and sittingStage=="Sitting":
sittingStage = "Standing"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: sittingStage



# CALCULATE FPS
cTime = time.time()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: cTime

# CALCULATE FPS
cTime = time.time()
fps = 1/(cTime-pTime)
pTime = cTime
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: pTime

Updated variable names to follow appropriate python naming convention
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

# FEED CAPTURE
cap = cv2.VideoCapture(0) # Webcam feed
#cap = cv2.VideoCapture('Videos/3.mp4')
p_Time = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: p_Time


# Resolution scaling

def make_1080p()-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_1080p


make_1080p()

def make_720p()-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_720p

cap.set(3, 1280)
cap.set(4, 720)

def make_480p()-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_480p


#make_480p()

def change_res(width, height)-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function change_res

Please provide type hint for the parameter: width

Please provide type hint for the parameter: height

back_Stage = "Straight"
if backAngle1 < 174 and backAngle2 < 174 and back_Stage1 == back_Stage2 =='Straight':
back_Stage1 = "Crooked"
back_Stage2 = "Crooked"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: back_Stage2

if backAngle1 < 174 and backAngle2 < 174 and back_Stage1 == back_Stage2 =='Straight':
back_Stage1 = "Crooked"
back_Stage2 = "Crooked"
backColor = red
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backColor

back_Stage1 = "Crooked"
back_Stage2 = "Crooked"
backColor = red
back_Stage = "Crooked"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: back_Stage



# CALCULATE FPS
c_Time = time.time()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: c_Time

# CALCULATE FPS
c_Time = time.time()
fps = 1/(c_Time-p_Time)
p_Time = c_Time
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: p_Time

More changes in variable naming
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.


# Resolution scaling

def make_1080p()-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function make_1080p

white = (255,255,255)
color1 = (0,255,0)
color2 = (0,255,0)
backColor = (255,255,255)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backColor

# ANGLE CALCULATIONS

# X-Y PLANE
def calculate_angle(a, b, c)-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function calculate_angle

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide descriptive name for the parameter: b

Please provide type hint for the parameter: b

Please provide descriptive name for the parameter: c

Please provide type hint for the parameter: c



# Y-Z PLANE
def calculate_angle_yz(a, b, c)-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function calculate_angle_yz

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide descriptive name for the parameter: b

Please provide type hint for the parameter: b

Please provide descriptive name for the parameter: c

Please provide type hint for the parameter: c



# X-Z PLANE
def calculate_angle_xz(a, b, c)-> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/mediapipeDetection.py, please provide doctest for the function calculate_angle_xz

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide descriptive name for the parameter: b

Please provide type hint for the parameter: b

Please provide descriptive name for the parameter: c

Please provide type hint for the parameter: c

lElbowAngleYZ = "YZ: " + str(int(calculate_angle_yz(lshoulder, lelbow, lwrist)))
rElbowAngleYZ = "YZ: " + str(int(calculate_angle_yz(rshoulder, relbow, rwrist)))
lShoulderAngleYZ = "YZ:" + str(int(calculate_angle_yz(lhip, lshoulder, lelbow)))
rShoulderAngleYZ = "YZ:" + str(int(calculate_angle_yz(rhip, rshoulder, relbow)))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: rShoulderAngleYZ

angle4 = int(calculate_angle(rhip, rknee, rankle))


backAngle1 = int(calculate_angle(lshoulder, lhip, lknee))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backAngle1



backAngle1 = int(calculate_angle(lshoulder, lhip, lknee))
backAngle2 = int(calculate_angle(rshoulder, rhip, rknee))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backAngle2

if backAngle1 > 174 and backAngle2 > 174:
back_stage1 = "Straight"
back_stage2 = "Straight"
backColor = white
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backColor

if backAngle1 < 174 and backAngle2 < 174 and back_stage1 == back_stage2 =='Straight':
back_stage1 = "Crooked"
back_stage2 = "Crooked"
backColor = red
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: backColor

@cclauss cclauss closed this Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
X Tutup