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
c537eee6
Commit
c537eee6
authored
Mar 12, 2022
by
IT19165226-Arachchige I.D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Live Feed - Printing nose landmark 3d coordinates into a csv file
parent
3f1f6db7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
1 deletion
+97
-1
Head Pose Estimation - Live Analysis.ipynb
Head Pose Estimation - Live Analysis.ipynb
+97
-1
No files found.
Head Pose Estimation - Live Analysis.ipynb
View file @
c537eee6
...
...
@@ -78,7 +78,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "
d27b1da2
",
"id": "
fe0bc52d
",
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -116,6 +116,102 @@
" cap.release() \n",
" cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8550701",
"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",
"#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",
" #landmark_full_desc = landmarks[mp_pose.PoseLandmark.NOSE.value]\n",
" \n",
" #creating a list of the coordinates where the nose has been\n",
" nose_landmark_full_desc.append(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",
" 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",
"\n",
" cap.release() \n",
" cv2.destroyAllWindows()\n",
" \n",
"#print(nose_landmark_full_desc)\n",
"#print(landmark_full_desc.x) -- if only one set of coordinates"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03ed7d0b",
"metadata": {},
"outputs": [],
"source": [
"##writing details to the CV\n",
"\n",
"#%%file 11_A_FT_M.csv\n",
"#Frame_number,x_coordinate,y_coordinate,z_coordinate\n",
"\n",
"#creating the csv template\n",
"with open('live_feed.csv', mode='w', newline='') as headpose_track_file:\n",
" writer = csv.writer(headpose_track_file) #, delimiter=',', quotechar='\"', quoting = csv.QUOTE_MINIMAL)\n",
" writer.writerow(['Frame_number','x_coordinate','y_coordinate', 'z_coordinate'])\n",
"\n",
"#writing the data to a csv\n",
"with open('live_feed.csv', mode='a', newline='') as headpose_track_file:\n",
" writer = csv.writer(headpose_track_file)\n",
" \n",
" #looping through all records of nose coordinate details\n",
" for record in nose_landmark_full_desc:\n",
" frameNo += 1 #increase the frame number\n",
" #writing the record details to the file\n",
" writer.writerow([frameNo, record.x, record.y, record.z])"
]
}
],
"metadata": {
...
...
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