Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ededb7a

Browse files
Added path functionality so users can use their own paths
1 parent fc16670 commit ededb7a

File tree

1 file changed

+30
-235
lines changed

1 file changed

+30
-235
lines changed

Prototype_2_Electric_Boogalooo.ipynb

Lines changed: 30 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"colab": {
66
"provenance": [],
77
"mount_file_id": "1YJfEK8zha4PfUk2yP9y-XbO4vtmn83gE",
8-
"authorship_tag": "ABX9TyOxdY25CPapUx8uMRKR6IDa",
8+
"authorship_tag": "ABX9TyOBWPsdBZG7A+YZa8hU7Fjw",
99
"include_colab_link": true
1010
},
1111
"kernelspec": {
@@ -40,49 +40,39 @@
4040
"cell_type": "code",
4141
"execution_count": null,
4242
"metadata": {
43-
"id": "gmwahO7oITMz",
44-
"outputId": "5a88f36a-ef77-4550-ee4f-2dee36b2526d",
45-
"colab": {
46-
"base_uri": "https://localhost:8080/"
47-
}
43+
"id": "gmwahO7oITMz"
4844
},
49-
"outputs": [
50-
{
51-
"output_type": "stream",
52-
"name": "stdout",
53-
"text": [
54-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m33.9/33.9 MB\u001b[0m \u001b[31m11.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
55-
"\u001b[?25h"
56-
]
57-
}
58-
],
45+
"outputs": [],
5946
"source": [
6047
"!pip install -q mediapipe==0.10.0"
6148
]
6249
},
50+
{
51+
"cell_type": "markdown",
52+
"source": [
53+
"Make sure a copy of the **Fit Form AI Resources** folder is in your personal Drive or at the relevant directory before the next step\n",
54+
"\n",
55+
"Folder can be found here: https://drive.google.com/drive/folders/1RFTh9ed50zVZaIyutPCo6-VTEQanqE4_?usp=sharing"
56+
],
57+
"metadata": {
58+
"id": "e1sSWM10JfE7"
59+
}
60+
},
6361
{
6462
"cell_type": "code",
6563
"source": [
6664
"from google.colab import drive\n",
67-
"drive.mount('/content/drive')"
65+
"drive.mount('/content/drive')\n",
66+
"root_path = '/content/drive/MyDrive'\n",
67+
"\n",
68+
"if input(\"Are you using your local drive without any subfolders? (Y / N)\\n\") != 'Y': # Don't include the Fit Form AI Resources folder itself\n",
69+
" root_path = input(\"Enter path to the Fit Form AI Resources folder:\\n\")"
6870
],
6971
"metadata": {
70-
"id": "8xGt3oqXze3o",
71-
"colab": {
72-
"base_uri": "https://localhost:8080/"
73-
},
74-
"outputId": "34c50804-976f-484f-fbe1-32b9669dbbd6"
72+
"id": "8xGt3oqXze3o"
7573
},
7674
"execution_count": null,
77-
"outputs": [
78-
{
79-
"output_type": "stream",
80-
"name": "stdout",
81-
"text": [
82-
"Mounted at /content/drive\n"
83-
]
84-
}
85-
]
75+
"outputs": []
8676
},
8777
{
8878
"cell_type": "markdown",
@@ -173,7 +163,7 @@
173163
" # Calculates the angles the exercise requires (determines necessity if weight value signals its needed)\n",
174164
" # Compares the calculated angle with the min-max of the exercise\n",
175165
" def feedback(self, exercise):\n",
176-
" with open(f'/content/drive/MyDrive/Fit Form AI Resources/CSV Files/{exercise}.csv') as anglefile:\n",
166+
" with open(root_path + f'/Fit Form AI Resources/CSV Files/{exercise}.csv') as anglefile:\n",
177167
" anglereader = csv.reader(anglefile)\n",
178168
" for row in anglereader:\n",
179169
" # First check to see if you should calculate the angle\n",
@@ -291,19 +281,6 @@
291281
"execution_count": null,
292282
"outputs": []
293283
},
294-
{
295-
"cell_type": "markdown",
296-
"source": [
297-
"Make sure to import **Pose Landmarker Lite** into Drive folder before next step\n",
298-
"\n",
299-
"Can be found in Drive folder: https://drive.google.com/drive/folders/1RFTh9ed50zVZaIyutPCo6-VTEQanqE4_?usp=sharing\n",
300-
"\n",
301-
"If needed, download latest from MediaPipe website: https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/index#models"
302-
],
303-
"metadata": {
304-
"id": "e1sSWM10JfE7"
305-
}
306-
},
307284
{
308285
"cell_type": "markdown",
309286
"source": [
@@ -316,7 +293,7 @@
316293
{
317294
"cell_type": "code",
318295
"source": [
319-
"model_path = f'/content/drive/MyDrive/Fit Form AI Resources/pose_landmarker_{input(\"What model to use? \")}.task'"
296+
"model_path = root_path + f'/Fit Form AI Resources/pose_landmarker_{input(\"What model to use? \")}.task'"
320297
],
321298
"metadata": {
322299
"id": "Zng2DvUJcJjc",
@@ -339,9 +316,7 @@
339316
{
340317
"cell_type": "markdown",
341318
"source": [
342-
"If you would like to save a video of the live camera feed, type **'Y'** below. If not, **'N'** or leave blank.\n",
343-
"\n",
344-
"***Note: Videos are saved in a PUBLIC GitHub repo with little option for deletion. Once a recording is made, expect it to stay there.***"
319+
"If you would like to save a video of the live camera feed, type **'Y'** below. If not, **'N'** or leave blank."
345320
],
346321
"metadata": {
347322
"id": "-VP0c854aaGl"
@@ -351,8 +326,10 @@
351326
"cell_type": "code",
352327
"source": [
353328
"record = False\n",
329+
"vid_path = ''\n",
354330
"if input(\"Would you like to record and save the video you create below? (Y / N)\\n\") == 'Y':\n",
355-
" record = True"
331+
" record = True\n",
332+
" vid_path = root_path + '/Fit Form AI Resources/Videos/'"
356333
],
357334
"metadata": {
358335
"id": "brFyKQV5aEuK"
@@ -370,7 +347,7 @@
370347
"PoseLandmarkerResult = vision.PoseLandmarkerResult # Stores result from model\n",
371348
"out_video = None\n",
372349
"if record:\n",
373-
" out_video = cv.VideoWriter('/content/drive/MyDrive/Fit Form AI Resources/Videos/' + time.asctime(time.localtime()) + '.mp4',cv.VideoWriter_fourcc(*'DIVX'), 24, (640, 480))\n",
350+
" out_video = cv.VideoWriter(vid_path + time.asctime(time.localtime()) + '.mp4',cv.VideoWriter_fourcc(*'DIVX'), 24, (640, 480))\n",
374351
"landmarks_list = []\n",
375352
"feedback_list = [\"\"]\n",
376353
"selected_exercise = input(\"What exercise are you tracking?\\n\")\n",
@@ -552,192 +529,10 @@
552529
" out_video.release()"
553530
],
554531
"metadata": {
555-
"id": "GHzmhoO6Jc50",
556-
"colab": {
557-
"base_uri": "https://localhost:8080/",
558-
"height": 856
559-
},
560-
"outputId": "4d009091-47a2-49c6-e8e8-70a776fb6d19"
532+
"id": "GHzmhoO6Jc50"
561533
},
562534
"execution_count": null,
563-
"outputs": [
564-
{
565-
"name": "stdout",
566-
"output_type": "stream",
567-
"text": [
568-
"What exercise are you tracking?\n",
569-
"Push Up\n"
570-
]
571-
},
572-
{
573-
"output_type": "display_data",
574-
"data": {
575-
"text/plain": [
576-
"<IPython.core.display.Javascript object>"
577-
],
578-
"application/javascript": [
579-
"\n",
580-
" var video;\n",
581-
" var div = null;\n",
582-
" var stream;\n",
583-
" var captureCanvas;\n",
584-
" var imgElement;\n",
585-
" var labelElement;\n",
586-
"\n",
587-
" var pendingResolve = null;\n",
588-
" var shutdown = false;\n",
589-
"\n",
590-
" function removeDom() {\n",
591-
" stream.getVideoTracks()[0].stop();\n",
592-
" video.remove();\n",
593-
" div.remove();\n",
594-
" video = null;\n",
595-
" div = null;\n",
596-
" stream = null;\n",
597-
" imgElement = null;\n",
598-
" captureCanvas = null;\n",
599-
" labelElement = null;\n",
600-
" }\n",
601-
"\n",
602-
" function onAnimationFrame() {\n",
603-
" if (!shutdown) {\n",
604-
" window.requestAnimationFrame(onAnimationFrame);\n",
605-
" }\n",
606-
" if (pendingResolve) {\n",
607-
" var result = \"\";\n",
608-
" if (!shutdown) {\n",
609-
" captureCanvas.getContext('2d').drawImage(video, 0, 0, 640, 480);\n",
610-
" result = captureCanvas.toDataURL('image/jpeg', 0.8)\n",
611-
" }\n",
612-
" var lp = pendingResolve;\n",
613-
" pendingResolve = null;\n",
614-
" lp(result);\n",
615-
" }\n",
616-
" }\n",
617-
"\n",
618-
" async function createDom() {\n",
619-
" if (div !== null) {\n",
620-
" return stream;\n",
621-
" }\n",
622-
" div = document.createElement('div');\n",
623-
" div.style.border = '2px solid black';\n",
624-
" div.style.padding = '3px';\n",
625-
" div.style.width = '100%';\n",
626-
" div.style.maxWidth = '600px';\n",
627-
" document.body.appendChild(div);\n",
628-
"\n",
629-
"\n",
630-
" video = document.createElement('video');\n",
631-
" video.style.display = 'block';\n",
632-
" video.width = div.clientWidth - 6;\n",
633-
" video.setAttribute('playsinline', '');\n",
634-
" video.onclick = () => { shutdown = true; };\n",
635-
" stream = await navigator.mediaDevices.getUserMedia(\n",
636-
" {video: { facingMode: \"environment\"}});\n",
637-
" div.appendChild(video);\n",
638-
" imgElement = document.createElement('img');\n",
639-
" imgElement.style.position = 'absolute';\n",
640-
" imgElement.style.zIndex = 1;\n",
641-
" imgElement.onclick = () => { shutdown = true; };\n",
642-
" div.appendChild(imgElement);\n",
643-
"\n",
644-
" const instruction = document.createElement('div');\n",
645-
" instruction.innerHTML =\n",
646-
" '<span style=\"blue: red; font-weight: bold;\">' +\n",
647-
" 'click here to stop the video</span>';\n",
648-
" div.appendChild(instruction);\n",
649-
" instruction.onclick = () => { shutdown = true; };\n",
650-
"\n",
651-
" video.srcObject = stream;\n",
652-
" await video.play();\n",
653-
" captureCanvas = document.createElement('canvas');\n",
654-
" captureCanvas.width = 640;\n",
655-
" captureCanvas.height = 480;\n",
656-
" window.requestAnimationFrame(onAnimationFrame);\n",
657-
"\n",
658-
" return stream;\n",
659-
" }\n",
660-
" async function stream_frame() {\n",
661-
" if (shutdown) {\n",
662-
" removeDom();\n",
663-
" shutdown = false;\n",
664-
" return '';\n",
665-
" }\n",
666-
" var preCreate = Date.now();\n",
667-
" stream = await createDom();\n",
668-
"\n",
669-
" var preShow = Date.now();\n",
670-
"\n",
671-
"\n",
672-
"\n",
673-
" var preCapture = Date.now();\n",
674-
" var result = await new Promise(function(resolve, reject) {\n",
675-
" pendingResolve = resolve;\n",
676-
" });\n",
677-
" shutdown = false;\n",
678-
"\n",
679-
" return {'create': preShow - preCreate,\n",
680-
" 'show': preCapture - preShow,\n",
681-
" 'capture': Date.now() - preCapture,\n",
682-
" 'img': result};\n",
683-
" }\n",
684-
" "
685-
]
686-
},
687-
"metadata": {}
688-
},
689-
{
690-
"output_type": "stream",
691-
"name": "stdout",
692-
"text": [
693-
"Left Arm Isn't Visible\n",
694-
"Right Arm Isn't Visible\n",
695-
"Left Arm Isn't Visible\n",
696-
"Right Arm Isn't Visible\n",
697-
"Left Arm Isn't Visible\n",
698-
"Right Arm Isn't Visible\n",
699-
"Left Arm Isn't Visible\n",
700-
"Right Arm Isn't Visible\n",
701-
"Left Arm Isn't Visible\n",
702-
"Right Arm Isn't Visible\n",
703-
"Left Arm Isn't Visible\n",
704-
"Right Arm Isn't Visible\n",
705-
"Left Arm Isn't Visible\n",
706-
"Right Arm Isn't Visible\n",
707-
"Left Arm Isn't Visible\n",
708-
"Right Arm Isn't Visible\n",
709-
"Left Arm Isn't Visible\n",
710-
"Right Arm Isn't Visible\n",
711-
"Try Straightening Your Arm Somewhat\n",
712-
"Right Arm Isn't Visible\n",
713-
"Try Straightening Your Arm Somewhat\n",
714-
"Left Arm Isn't Visible\n",
715-
"Right Arm Isn't Visible\n",
716-
"Try Straightening Your Hip Somewhat\n",
717-
"Try Straightening Your Arm Somewhat\n",
718-
"Try Straightening Your Hip Somewhat\n",
719-
"Try Straightening Your Arm Somewhat\n",
720-
"Right Leg Isn't Visible\n",
721-
"Try Straightening Your Arm Somewhat\n",
722-
"Try Straightening Your Hip Somewhat\n",
723-
"Try Spreading Your Arms Out More\n",
724-
"Good Form\n",
725-
"Try Straightening Your Legs More\n",
726-
"Try Spreading Your Arms Out More\n",
727-
"Good Form\n",
728-
"Try Spreading Your Arms Out More\n",
729-
"Good Form\n",
730-
"Try Spreading Your Arms Out More\n",
731-
"Good Form\n",
732-
"Try Spreading Your Arms Out More\n",
733-
"Try Straightening Your Arm Somewhat\n",
734-
"Try Spreading Your Arms Out More\n",
735-
"Good Form\n",
736-
"Right Leg Isn't Visible\n",
737-
"Try Straightening Your Hip Somewhat\n"
738-
]
739-
}
740-
]
535+
"outputs": []
741536
}
742537
]
743538
}

0 commit comments

Comments
 (0)