Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-074
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-074
2022-074
Commits
b31994b8
Commit
b31994b8
authored
May 09, 2022
by
IT19165226-Arachchige I.D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test commit -3
parent
4540c4e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
248 additions
and
0 deletions
+248
-0
VideoAnalysis.ipynb
VideoAnalysis.ipynb
+248
-0
No files found.
VideoAnalysis.ipynb
0 → 100644
View file @
b31994b8
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "90e3f5ea",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: mediapipe in c:\\users\\isuri\\anaconda3\\lib\\site-packages (0.8.9.1)\n",
"Requirement already satisfied: OpenCV-python in c:\\users\\isuri\\anaconda3\\lib\\site-packages (4.5.5.64)\n",
"Requirement already satisfied: matplotlib in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (3.4.3)\n",
"Requirement already satisfied: numpy in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (1.20.3)\n",
"Requirement already satisfied: protobuf>=3.11.4 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (3.20.1)\n",
"Requirement already satisfied: attrs>=19.1.0 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (21.2.0)\n",
"Requirement already satisfied: absl-py in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (1.0.0)\n",
"Requirement already satisfied: opencv-contrib-python in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from mediapipe) (4.5.5.64)\n",
"Requirement already satisfied: six in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from absl-py->mediapipe) (1.16.0)\n",
"Requirement already satisfied: pyparsing>=2.2.1 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from matplotlib->mediapipe) (3.0.4)\n",
"Requirement already satisfied: pillow>=6.2.0 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from matplotlib->mediapipe) (8.4.0)\n",
"Requirement already satisfied: python-dateutil>=2.7 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from matplotlib->mediapipe) (2.8.2)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from matplotlib->mediapipe) (1.3.1)\n",
"Requirement already satisfied: cycler>=0.10 in c:\\users\\isuri\\anaconda3\\lib\\site-packages (from matplotlib->mediapipe) (0.10.0)\n"
]
}
],
"source": [
"!pip install mediapipe OpenCV-python"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b6068954",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import mediapipe as mp\n",
"import numpy as np\n",
"mp_drawing = mp.solutions.drawing_utils\n",
"mp_pose = mp.solutions.pose"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "835fb8e2",
"metadata": {},
"outputs": [],
"source": [
"#Video Feed\n",
"\n",
"#setting up video feed device\n",
"#number in VideoCapture = number of device\n",
"cap = cv2.VideoCapture(0) \n",
"while cap.isOpened():\n",
" ret, frame = cap.read() #get current feed from device\n",
" cv2.imshow('Mediapipe Feed', frame) #pop-up to visualize the feed\n",
"\n",
" if cv2.waitKey(10) & 0xFF == ord('q'): #to close the feed\n",
" break\n",
"\n",
"cap.release() #release the webcam\n",
"cv2.destroyAllWindows()\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ca4a3c1c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello\n"
]
}
],
"source": [
"print('Hello')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "117dec2d",
"metadata": {},
"outputs": [],
"source": [
"#Video Feed\n",
"\n",
"#setting up video feed device\n",
"#number in VideoCapture = number of device\n",
"cap = cv2.VideoCapture(0) \n",
"#set up media pipe instance\n",
"with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:\n",
" while cap.isOpened():\n",
" ret, frame = cap.read() #get current feed from device\n",
"\n",
" #detect stuff and render\n",
" image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) #recolouring image\n",
" image.flags.writeable = False\n",
"\n",
" #make detection\n",
" results = pose.process(image)\n",
"\n",
" #recolouring image to format required by openCV\n",
" image.flags.writeable = True\n",
" image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n",
"\n",
" #render image\n",
" #draw landmarks\n",
" mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,\n",
" mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2), #changing the colours of the dots, default is green\n",
" mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2)) #changing the colours of the connecting lines\n",
" cv2.imshow('Mediapipe Feed', image) #pop-up to visualize the feed\n",
"\n",
" if cv2.waitKey(10) & 0xFF == ord('q'): #to close the feed\n",
" break\n",
"\n",
" cap.release() \n",
" cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "17b488db",
"metadata": {},
"outputs": [],
"source": [
"#Video Feed\n",
"\n",
"#setting up video feed device\n",
" #number in VideoCapture = number of device\n",
"cap = cv2.VideoCapture(0) \n",
"\n",
"#processing a video\n",
"#VIDEO_STREAM = '/content/drive/MyDrive/Research_Project/videos/LRH_video_02.mp4'\n",
"#video_name = 'LRH_video_02'\n",
"#output_folder = '/content/drive/MyDrive/Research_Project/results/LRH_video_02'\n",
"\n",
"#print(f\"[INFO] Processing {video_name}...\")\n",
"#VIDEO_STREAM_OUT = os.path.join(output_folder , video_name + '_MP.mp4')\n",
"#graph_plot = os.path.join(output_folder , video_name+'_MP.png')\n",
"#cap = cv2.VideoCapture(VIDEO_STREAM)\n",
"\n",
"#fourcc = cv2.VideoWriter_fourcc(*\"XVID\")\n",
"\n",
"frameNo = 0\n",
"\n",
"\n",
"#set up media pipe instance\n",
"with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:\n",
" while cap.isOpened():\n",
" ret, frame = cap.read() #get current feed from device\n",
"\n",
" ++frameNo #increase the frame number\n",
"\n",
" #detect stuff and render\n",
" image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) #recolouring image\n",
" image.flags.writeable = False\n",
"\n",
" #make detection\n",
" results = pose.process(image)\n",
"\n",
" #recolouring image to format required by openCV\n",
" image.flags.writeable = True\n",
" image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n",
"\n",
" #extract landmarks\n",
" try:\n",
" landmarks = results.pose_landmarks.landmark\n",
" #print(landmarks)\n",
"\n",
" #to print a specific coordinate\n",
" landmarks[mp_pose.PoseLandmark.NOSE.value]\n",
" \n",
" #getting a specific axis of a given landmark\n",
" x_coordinate = [landmarks[mp_pose.PoseLandmark.NOSE.value].x]\n",
" y_coordinate = [landmarks[mp_pose.PoseLandmark.NOSE.value].y]\n",
" z_coordinate = [landmarks[mp_pose.PoseLandmark.NOSE.value].z]\n",
" \n",
" print('X: ' + landmarks[mp_pose.PoseLandmark.NOSE.value].x)\n",
" print(landmarks[mp_pose.PoseLandmark.NOSE.value].x)\n",
" \n",
" #print('Nose Co-ordinates: ' + x_coordinate, ', ' + y_coordinate + ', ' + z_coordinate) --- doesn't work?\n",
"\n",
" #Writing data to the csv file of a given landmark\n",
" with open('11_A_FT_M.csv', mode='w') as object_track_file:\n",
" OT_writer = csv.writer(object_track_file, delimiter=',', quotechar='\"', quoting = csv.QUOTE_MINIMAL)\n",
" OT_writer.writerow(['Frame_number','x_coordinate','y_coordinate', 'z_coordinate'])\n",
" OT_writer.writerow([frameNo, x_coordinate, y_coordinate, z_coordinate])\n",
"\n",
" except:\n",
" pass\n",
"\n",
" #render image\n",
" #draw landmarks\n",
" mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,\n",
" mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2), #changing the colours of the dots, default is green\n",
" mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2)) #changing the colours of the connecting lines\n",
" cv2.imshow('Mediapipe Feed', image) #pop-up to visualize the feed\n",
"\n",
" if cv2.waitKey(10) & 0xFF == ord('q'): #to close the feed\n",
" break\n",
"\n",
" cap.release() \n",
" cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75dcebc6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment