Giter VIP home page Giter VIP logo

Comments (9)

github-actions avatar github-actions commented on July 23, 2024

👋 Hello @srinidhi0476, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

from ultralytics.

srinidhi0476 avatar srinidhi0476 commented on July 23, 2024

Good evening
I am using YOLOv8 AIGYM model for calculating the joint angle. Elbow and Shoulder angle is detecting. I want Hip, Knee, Neck angles. Below I provided the code. Suggest me how to get knee, hip, neck angles for video file. Do needfull

from ultralytics.

glenn-jocher avatar glenn-jocher commented on July 23, 2024

Good evening!

Thank you for reaching out and providing your code example. It's great to hear that you're using the YOLOv8 AIGYM model for joint angle detection! To calculate the angles for the hip, knee, and neck, you can adjust the kpts_to_check parameter to include the keypoints corresponding to these joints.

Here's a brief guide on how to set up the keypoints for hip, knee, and neck angles:

  • Hip Angle: Typically involves keypoints for the hip, knee, and shoulder.
  • Knee Angle: Involves keypoints for the knee, hip, and ankle.
  • Neck Angle: Involves keypoints for the neck, shoulder, and head.

Below is an updated version of your code to include these angles:

from ultralytics import YOLO
from ultralytics.solutions import ai_gym
import cv2

model = YOLO("yolov8n-pose.pt")
cap = cv2.VideoCapture("S:/Field video for RULA and REBA/Sudha Babai/Sudha digging traditional right.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

# Initialize AI Gym module for hip angle measurement
gym_object_hip = ai_gym.AIGym()
gym_object_hip.set_args(line_thickness=2, view_img=True, pose_type="pushup", kpts_to_check=[12, 14, 16])  # Hip, Knee, Ankle

# Initialize AI Gym module for knee angle measurement
gym_object_knee = ai_gym.AIGym()
gym_object_knee.set_args(line_thickness=2, view_img=True, pose_type="pushup", kpts_to_check=[14, 12, 24])  # Knee, Hip, Shoulder

# Initialize AI Gym module for neck angle measurement
gym_object_neck = ai_gym.AIGym()
gym_object_neck.set_args(line_thickness=2, view_img=True, pose_type="pushup", kpts_to_check=[0, 6, 8])  # Head, Shoulder, Neck

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    frame_count += 1
    results = model.track(im0, verbose=False)  # Tracking recommended
    
    # Calculate angles
    im0 = gym_object_hip.start_counting(im0, results, frame_count)
    im0 = gym_object_knee.start_counting(im0, results, frame_count)
    im0 = gym_object_neck.start_counting(im0, results, frame_count)
    
    if frame_count % 20 == 0:
        cv2.imwrite("Frame_" + str(frame_count) + ".png", im0)
     
cv2.destroyAllWindows()

In this code:

  • kpts_to_check for the hip angle is set to [12, 14, 16] (hip, knee, ankle).
  • kpts_to_check for the knee angle is set to [14, 12, 24] (knee, hip, shoulder).
  • kpts_to_check for the neck angle is set to [0, 6, 8] (head, shoulder, neck).

Feel free to adjust the keypoint indices based on your specific requirements. For more detailed information on keypoints and their indices, you can refer to the Ultralytics documentation.

If you encounter any issues or need further assistance, please let us know. We're here to help! 😊

from ultralytics.

srinidhi0476 avatar srinidhi0476 commented on July 23, 2024

Yes sir. I got the angles thank you. another one question how to remove the white rectangular box in which joint angle text is indicating and I want to remove the step and up , down display on screen. I will attach the image below.
Uploading Frame_200.png…

from ultralytics.

glenn-jocher avatar glenn-jocher commented on July 23, 2024

@srinidhi0476 hello!

I'm glad to hear that you were able to get the angles working! 😊

To remove the white rectangular box displaying the joint angle text and to hide the step and up/down indicators, you can modify the AIGym class to skip the drawing of these elements. Below is an example of how you can achieve this:

  1. Remove the White Rectangular Box and Text:

    • You can comment out or remove the lines in the plot_angle_and_count_and_stage method that draw the box and text.
  2. Remove the Step and Up/Down Display:

    • Similarly, you can comment out or remove the lines that draw the step and up/down indicators.

Here's an example of how you can modify the AIGym class:

class AIGym:
    """A class to manage the gym steps of people in a real-time video stream based on their poses."""

    def __init__(
        self,
        kpts_to_check,
        line_thickness=2,
        view_img=False,
        pose_up_angle=145.0,
        pose_down_angle=90.0,
        pose_type="pullup",
    ):
        # Initialization code remains the same
        ...

    def start_counting(self, im0, results, frame_count):
        # Function used to count the gym steps
        ...

        for ind, k in enumerate(reversed(self.keypoints)):
            # Estimate angle and draw specific points based on pose type
            if self.pose_type in {"pushup", "pullup", "abworkout", "squat"}:
                self.angle[ind] = self.annotator.estimate_pose_angle(
                    k[int(self.kpts_to_check[0])].cpu(),
                    k[int(self.kpts_to_check[1])].cpu(),
                    k[int(self.kpts_to_check[2])].cpu(),
                )
                self.im0 = self.annotator.draw_specific_points(k, self.kpts_to_check, shape=(640, 640), radius=10)

                # Check and update pose stages and counts based on angle
                if self.pose_type in {"abworkout", "pullup"}:
                    if self.angle[ind] > self.poseup_angle:
                        self.stage[ind] = "down"
                    if self.angle[ind] < self.posedown_angle and self.stage[ind] == "down":
                        self.stage[ind] = "up"
                        self.count[ind] += 1

                elif self.pose_type in {"pushup", "squat"}:
                    if self.angle[ind] > self.poseup_angle:
                        self.stage[ind] = "up"
                    if self.angle[ind] < self.posedown_angle and self.stage[ind] == "up":
                        self.stage[ind] = "down"
                        self.count[ind] += 1

                # Comment out or remove the following lines to hide the text and boxes
                # self.annotator.plot_angle_and_count_and_stage(
                #     angle_text=self.angle[ind],
                #     count_text=self.count[ind],
                #     stage_text=self.stage[ind],
                #     center_kpt=k[int(self.kpts_to_check[1])],
                # )

            # Draw keypoints
            self.annotator.kpts(k, shape=(640, 640), radius=1, kpt_line=True)

        # Display the image if environment supports it and view_img is True
        if self.env_check and self.view_img:
            cv2.imshow("Ultralytics YOLOv8 AI GYM", self.im0)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                return

        return self.im0

By commenting out the plot_angle_and_count_and_stage method call, you will remove the white rectangular box and the step/up/down display from the output.

Feel free to adjust the code further based on your specific requirements. If you have any more questions or need further assistance, don't hesitate to ask. We're here to help! 🚀

from ultralytics.

srinidhi0476 avatar srinidhi0476 commented on July 23, 2024

from ultralytics.

srinidhi0476 avatar srinidhi0476 commented on July 23, 2024

Frame_20
Above mentioned problem are not getting solved . please will you suggest me how to resolve this issues

from ultralytics.

glenn-jocher avatar glenn-jocher commented on July 23, 2024

Good afternoon @srinidhi0476,

Thank you for your patience and for providing additional details. Let's address the issues you're facing:

  1. Angles Changing for a Single Frame/Image:

    • This issue might be due to the way the angles are being calculated and displayed. Ensure that the keypoints are correctly identified and that the angle calculation is consistent. If the keypoints are fluctuating, it could cause the angles to change. You might want to add some smoothing or averaging to stabilize the keypoints.
  2. Removing the White Rectangular Box and Stage/Count Text:

    • To remove the stage and count text while keeping the angle display, you can modify the plot_angle_and_count_and_stage method to only draw the angle text. Here's how you can do it:
class AIGym:
    """A class to manage the gym steps of people in a real-time video stream based on their poses."""

    def __init__(
        self,
        kpts_to_check,
        line_thickness=2,
        view_img=False,
        pose_up_angle=145.0,
        pose_down_angle=90.0,
        pose_type="pullup",
    ):
        # Initialization code remains the same
        ...

    def start_counting(self, im0, results, frame_count):
        # Function used to count the gym steps
        ...

        for ind, k in enumerate(reversed(self.keypoints)):
            # Estimate angle and draw specific points based on pose type
            if self.pose_type in {"pushup", "pullup", "abworkout", "squat"}:
                self.angle[ind] = self.annotator.estimate_pose_angle(
                    k[int(self.kpts_to_check[0])].cpu(),
                    k[int(self.kpts_to_check[1])].cpu(),
                    k[int(self.kpts_to_check[2])].cpu(),
                )
                self.im0 = self.annotator.draw_specific_points(k, self.kpts_to_check, shape=(640, 640), radius=10)

                # Check and update pose stages and counts based on angle
                if self.pose_type in {"abworkout", "pullup"}:
                    if self.angle[ind] > self.poseup_angle:
                        self.stage[ind] = "down"
                    if self.angle[ind] < self.posedown_angle and self.stage[ind] == "down":
                        self.stage[ind] = "up"
                        self.count[ind] += 1

                elif self.pose_type in {"pushup", "squat"}:
                    if self.angle[ind] > self.poseup_angle:
                        self.stage[ind] = "up"
                    if self.angle[ind] < self.posedown_angle and self.stage[ind] == "up":
                        self.stage[ind] = "down"
                        self.count[ind] += 1

                # Modify this method to only display the angle text
                self.annotator.plot_angle_only(
                    angle_text=self.angle[ind],
                    center_kpt=k[int(self.kpts_to_check[1])],
                )

            # Draw keypoints
            self.annotator.kpts(k, shape=(640, 640), radius=1, kpt_line=True)

        # Display the image if environment supports it and view_img is True
        if self.env_check and self.view_img:
            cv2.imshow("Ultralytics YOLOv8 AI GYM", self.im0)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                return

        return self.im0

And in the annotator class, you can add the plot_angle_only method:

class Annotator:
    def plot_angle_only(self, angle_text, center_kpt):
        # Draw the angle text without the box and other text
        cv2.putText(
            self.im0,
            f"{angle_text:.1f}",
            (int(center_kpt[0]), int(center_kpt[1])),
            cv2.FONT_HERSHEY_SIMPLEX,
            0.5,
            (255, 255, 255),
            2,
            cv2.LINE_AA,
        )

This should help in displaying only the angle text without the white rectangular box and the stage/count text.

If you continue to face issues, please ensure you are using the latest versions of torch and ultralytics. If the problem persists, providing a minimum reproducible code example would be very helpful for further investigation. You can refer to our minimum reproducible example guide for more details.

Feel free to reach out if you have any more questions or need further assistance. We're here to help! 😊

from ultralytics.

github-actions avatar github-actions commented on July 23, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

from ultralytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.