יסודות בינה מלאכותית : RB29-09 – OPEN POSE YOLO
OPENPOSE YOLO
מה זה OpenPose ומה השימושים שלו בתעשייה?
OpenPose היא ספריית קוד פתוח מתקדמת לזיהוי תנוחות גוף, ידיים ופנים מתוך תמונות או סרטונים. המערכת משתמשת בלמידת מכונה כדי לזהות ולנתח נקודות מפתח בגוף האדם, כמו כתפיים, ברכיים, מרפקים, אצבעות ועוד.
שימושים עיקריים של OpenPose בתעשייה:
-
רפואה ושיקום – ניטור תנועות של מטופלים לצורך מעקב אחר תרגילים שיקומיים וזיהוי בעיות תנועה.
-
ספורט וביצועים – ניתוח תנועות ספורטאים לשיפור טכניקה, מניעת פציעות והדרכה חכמה.
-
משחקים ומציאות מדומה (VR) – מעקב אחרי תנועות גוף לשליטה אינטראקטיבית בדמויות.
-
אבטחה ובקרה – זיהוי תנוחות והתנהגויות חשודות מתוך מצלמות במעגל סגור.
-
אנימציה והפקות וידאו – לכידת תנועות גוף לצורך יצירת דמויות מונפשות או אפקטים מציאותיים.
OpenPose הפכה לכלי מרכזי בפרויקטים שמערבים חיבור בין אדם לטכנולוגיה, ומאפשרת רמה חדשה של אינטראקציה חכמה עם מערכות מחשב.
1 קישורים :
https://github.com/Alimustoofaa/YoloV8-Pose-Keypoint-Classification
2 .איך ניתן לנתח את את התמונות
3. קישור להורדת וידאו
https://y2meta.tube/convert/?videoId=esGZTeb_AiM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from ultralytics import YOLO import cv2 # Define keypoint names as per the model's standard output keypoint_names = [ "Nose", "Left Eye", "Right Eye", "Left Ear", "Right Ear", "Left Shoulder", "Right Shoulder", "Left Elbow", "Right Elbow", "Left Wrist", "Right Wrist", "Left Hip", "Right Hip", "Left Knee", "Right Knee", "Left Ankle", "Right Ankle" ] # Load the YOLOv8 pose model model = YOLO("yolov8n-pose.pt") # Ensure you have the YOLOv8 pose model downloaded # Load the image image_path = r"d:\temp\h1.jpg" image = cv2.imread(image_path) if image is None: print(f"Image not found at {image_path}") else: # Run pose detection results = model.predict(source=image, save=False, conf=0.5) # Extract and print keypoints with names for result in results: print("Detected Keypoints:") for i, (x, y, conf) in enumerate(result.keypoints.data[0]): # Check if the index is within the keypoint names list keypoint_name = keypoint_names[i] if i < len(keypoint_names) else f"Keypoint {i + 1}" print(f"{keypoint_name}: x={x:.2f}, y={y:.2f}, confidence={conf:.2f}") # Display the image with keypoints overlayed annotated_image = results[0].plot() cv2.imshow("Pose Detection", annotated_image) cv2.waitKey(0) cv2.destroyAllWindows() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
from ultralytics import YOLO import cv2 # Define keypoint names keypoint_names = [ "Nose", "Left Eye", "Right Eye", "Left Ear", "Right Ear", "Left Shoulder", "Right Shoulder", "Left Elbow", "Right Elbow", "Left Wrist", "Right Wrist", "Left Hip", "Right Hip", "Left Knee", "Right Knee", "Left Ankle", "Right Ankle" ] # Load YOLOv8 pose model model = YOLO("yolov8n-pose.pt") # Ensure the model file is in the same directory or provide the full path # Load the video file video_path = r"d:\temp\d2.mp4" output_path = r"d:\temp\output_pose_scaled.mp4" cap = cv2.VideoCapture(video_path) if not cap.isOpened(): print(f"Cannot open video file: {video_path}") else: # Get original frame width and height original_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) original_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = int(cap.get(cv2.CAP_PROP_FPS)) # Frame rate of the input video # Calculate new dimensions (40% smaller) scaled_width = int(original_width * 0.6) scaled_height = int(original_height * 0.6) # Set up the video writer fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4 output out = cv2.VideoWriter(output_path, fourcc, fps, (scaled_width, scaled_height)) while True: ret, frame = cap.read() if not ret: break # Resize frame (scale down by 40%) scaled_frame = cv2.resize(frame, (scaled_width, scaled_height)) # Run pose detection on the scaled frame results = model.predict(source=scaled_frame, save=False, conf=0.5) # Annotate the frame annotated_frame = results[0].plot() # Write the annotated frame to the output video out.write(annotated_frame) # Display the frame (optional, press 'q' to stop) cv2.imshow("Pose Detection (Scaled 40%)", annotated_frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() out.release() cv2.destroyAllWindows() print(f"Output video saved to {output_path}") |
תכנון מערכת בקרה בעזרת CHATGPT
- צפה בשתי הסרטונים האחד חישנים אידנקטבים , והשני חיישנים מגנטים
חיישן אינדוקטבי
זרם משתנה (AC או DC משתנה) יוצר שטף מגנטי משתנה, מה שנחוץ להשראת זרמים או מתח במעגלים סמוכים.
חוק לנץ (Lenz's Law) :
חיישן פוטואלקטרי
2.בנה בעזרת בינה מלאכותית מערכת של חיישנים למפעל – שיודעת לזהות סיבוב של זרוע רובוטית ללא מגע – איזה חיישן כדאי לקחת – בקש טבלה השוואה
3. בנה בעזרת בינה מלאוכתית מערכת למפעל מזון שבודקת אם יש חלילה נוכחות של ברגים או חלקי מתכת בתוך אוכל ? איזה חיישן נידרש
תרגיל כיתה 3 – מחיקת אובייקטים מתמונה
קישור לתוכנה : https://www.photoroom.com/
1.נעבד תמונה של בינה מלאכותית ונוסף לה טקסט ודמויות
קישור לתוכנה https://www.photopea.com/

1.הוספת טקסט לבינה מלאכותית
חלק 1
קישור לתוכנה https://www.photopea.com/
חלק 2
3. גזירה והדבקה של אובייקט
קישור לתוכנה https://www.photopea.com/
חדשות מהעולם :
https://www.ynet.co.il/activism/afterher2025/article/ry00imvt3yg#autoplay
https://www.mako.co.il/news-entertainment/2025_q1/Article-ff001cee7ecb591027.htm
תרגיל כיתה 2
1, הסר בעזרת בינה מלאוכתית רהיטים או חלקים שלא לטעמך
תמונה א
תמונה ב
2 שטול בתוך התמונה מוצר שלא קיים העזר ב CROP , הגד לבינה מלאוכתית ליצור את התמונה שאתה מבקש על קרע לבן שיהיה קל לעשות לה CROP
YOLO
תרגיל כיתה :
- הרץ בסביבת אנקונדה – פנה למרצה בכל שאלה
1 2 3 4 5 6 7 8 9 10 11 |
# Install required packages !pip install ultralytics opencv-python pillow --quiet # Imports from ultralytics import YOLO import cv2 from IPython.display import display, clear_output from PIL import Image import numpy as np print("✅ All packages installed and imported successfully.") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from ultralytics import YOLO from pathlib import Path # Load model model = YOLO('yolov8m.pt') # Image path image_path = Path(r'd:\temp\1.jpg') # Run detection results = model(image_path, save=True) # Get full path to saved image result_folder = Path(results[0].save_dir).resolve() result_image_name = Path(results[0].path).name result_image_path = result_folder / result_image_name # Print full path print("Result saved to:", result_image_path) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from ultralytics import YOLO # Load YOLOv8 model and run detection model = YOLO('yolov8n.pt') results = model(r'd:\temp\1.jpg') # Initialize people count people_count = 0 # Use a for loop to count people (class '0' is "person") for box in results[0].boxes: if box.cls[0] == 0: # Class '0' corresponds to "person" people_count += 1 # Print the count and appropriate message print("Low people" if people_count < 4 else "Many people") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from ultralytics import YOLO import cv2 # Load YOLOv8 model and run detection model = YOLO('yolov8n.pt') results = model(r'd:\temp\1.jpg') # Initialize people count and create an empty list for person boxes people_count = 0 person_boxes = [] # Use a for loop to count people with confidence > 60% and collect their boxes for box in results[0].boxes: if box.cls[0] == 0 and box.conf[0] > 0.6: # Class '0' is "person" and confidence > 60% people_count += 1 person_boxes.append(box) # Keep only high-confidence person boxes # Plot only the high-confidence person boxes annotated_img = results[0].orig_img.copy() for person_box in person_boxes: x1, y1, x2, y2 = map(int, person_box.xyxy[0]) # Convert to integer coordinates cv2.rectangle(annotated_img, (x1, y1), (x2, y2), (0, 255, 0), 2) # Add the people count to the image cv2.putText( annotated_img, f'People Count: {people_count}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2 ) # Display the annotated image cv2.imshow("People Detection", annotated_img) cv2.waitKey(0) # Wait until a key is pressed cv2.destroyAllWindows() # Close the window |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
from ultralytics import YOLO import cv2 from IPython.display import display, clear_output from PIL import Image import numpy as np # Load YOLOv8 model pre-trained on the COCO dataset model = YOLO('yolov8m.pt') # Load video file video_path = r'd:\temp\1.mp4' cap = cv2.VideoCapture(video_path) # Check if the video opened successfully if not cap.isOpened(): print("Error opening video file") # Process video frame-by-frame frame_count = 0 while cap.isOpened() and frame_count < 100: # Limiting to 100 frames for notebook display purposes ret, frame = cap.read() if not ret: break # Run YOLO detection on the frame results = model(frame) # Process each detected box and draw red rectangles for people above 60% confidence for box in results[0].boxes: if box.cls[0] == 0 and box.conf[0] > 0.6: # Class '0' is "person", confidence > 60% # Get the bounding box coordinates x1, y1, x2, y2 = map(int, box.xyxy[0]) # Convert to integer coordinates # Draw a red rectangle (bounding box) on the frame cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2) # Prepare the confidence text confidence_text = f"{box.conf[0] * 100:.1f}%" # Convert confidence to percentage with 1 decimal # Position the text slightly above the bounding box text_x, text_y = x1, y1 - 10 # Position above top-left corner of the bounding box cv2.putText( frame, confidence_text, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), # Red color for the text 2 ) # Convert the frame from BGR to RGB for Jupyter display frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) pil_img = Image.fromarray(frame_rgb) # Display the frame in the notebook clear_output(wait=True) display(pil_img) frame_count += 1 # Increase frame count to limit displayed frames # Release video capture cap.release() |