{"id":403,"date":"2023-05-02T10:09:00","date_gmt":"2023-05-02T10:09:00","guid":{"rendered":"https:\/\/rodamoya.com\/?p=403"},"modified":"2023-05-26T07:20:23","modified_gmt":"2023-05-26T07:20:23","slug":"caga-tio","status":"publish","type":"post","link":"https:\/\/rodamoya.com\/index.php\/2023\/05\/02\/caga-tio\/","title":{"rendered":"<strong>Caga tio:<\/strong>"},"content":{"rendered":"\n<p>Caga ti\u00f3 is a character in Catalan mythology relating to a Christmas tradition widespread in Catalonia. Created to expand the Catalan tradition without the need of traveling with a huge tronc in a plane\/car, this code created a virtual reality caga ti\u00f3. The program uses the cv2 library that does motion tracking. Detecting the different parts of the body, we are going to interact with the pictures that appear on the screen.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/04\/Peliculas-y-TV-2023-04-03-16-16-29_Trim-1.mp4\"><\/video><\/figure>\n\n\n\n<p>The steps of the code are based on the caga ti\u00f3 tradition process:<\/p>\n\n\n\n<p>     Step 1:<\/p>\n\n\n\n<p>Take the stick: If the coordinates of the hand pass through the stick, then print the stick in the coordinates of the hand.<\/p>\n\n\n\n<p>     Step 2:<\/p>\n\n\n\n<p>Heat the stick: If the coordinates of the stick are inside the oven, make a countdown of 5 seconds.<\/p>\n\n\n\n<p>     Step 3:<\/p>\n\n\n\n<p>Hit the caga ti\u00f3: If the coordinates of the stick are touching the caga ti\u00f3, it counts as a hit. The program takes around 12-15 hits to make the caga ti\u00f3 poop.<\/p>\n\n\n\n<p>     Step 4:<\/p>\n\n\n\n<p>Open the presents: Before executing the code, there is a variable &#8220;location_presents&#8221; to write where the presents are and make the person go and get them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import cv2\nimport mediapipe as mp\nimport time\n\nlocation_presents = \"Under the bed\"\n\ncap = cv2.VideoCapture(0)\n\n\nmpDraw = mp.solutions.drawing_utils\nmpPose = mp.solutions.pose\npose = mpPose.Pose()\n\ncount = 0\nhoven = 0\nstick = 0\npasss = 0\n\n# Restat variables:\npTime = 0\nlast_seg = 61\ni = 0\n\nx_list = &#91;]\ny_list = &#91;]\n\nwhile True:\n    # get the imatge from the camera and convert it to RGB\n    success, img = cap.read()\n    imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    results = pose.process(imgRGB)\n    \n    if results.pose_landmarks:\n        #Enumerate the difertns part ofthe body:\n        for id, lm in enumerate(results.pose_landmarks.landmark):\n            h, w, c = img.shape\n            cx, cy = int(lm.x * w) ,int(lm.y * h)\n            \n            \n            \n            #First level to take the stick:\n            if (hoven == 0) and (stick == 0):\n                \n                # Text:\n                cv2.putText(img, \"Take the stick :) \", (40, 150), cv2.FONT_HERSHEY_PLAIN, 3, (0,0,255), 3)\n                \n                # Stick:\n                cv2.line(img, (100, 250), (175, 150), (19,69,139), thickness = 10)\n      \n            # If left hand pass throug the stick, print it in the hand and level one passed:\n            if (id == 20) and (cx &gt; 100) and (cx &lt; 175) and (cy &gt; 150 ) and (cy &lt; 250) and (stick == 0):\n                \n                # Position of the stick:\n                stick_x_1 = cx - 75\n                stick_y_1 = cy - 100\n                \n                #Print stick:\n                cv2.line(img, (cx, cy), (stick_x_1, stick_y_1), (45,82,160), thickness = 10)\n                \n                # Pass the level\n                stick = 1\n            \n            # Level 2 put the stick in the hoven:\n            if (hoven == 0 ) and (stick == 1) and (id == 20):\n                \n                # Text:\n                cv2.putText(img, \"Put the stick in the oven\", (10, 150), cv2.FONT_HERSHEY_PLAIN, 2, (255,255,255), 3)\n                \n                # Positions stick:\n                stick_x_2 = cx - 90\n                stick_y_2 = cy - 10\n                \n                #Print new stick\n                cv2.line(img, (cx, cy), (stick_x_2, stick_y_2), (45,82,160), thickness = 10)\n                \n                \n                ## Print the Hoven \n                cv2.rectangle(img, pt1=(0,500), pt2=(350,250), color=(220,220,220), thickness= -1)               \n                cv2.rectangle(img, pt1=(50,450), pt2=(300,300), color=(0,0,0), thickness= -1)\n                cv2.rectangle(img, pt1=(50,360), pt2=(300,360), color=(90,90,90), thickness= -1)\n                cv2.rectangle(img, pt1=(50,390), pt2=(300,390), color=(90,90,90), thickness= -1)\n                cv2.rectangle(img, pt1=(50,420), pt2=(300,420), color=(90,90,90), thickness= -1)\n                cv2.rectangle(img, pt1=(150,310), pt2=(200,315), color=(100,100,100), thickness= -1)\n                \n                #cv2.line(img, (0, 300), (130, 300), (19,69,139), thickness = 9)  \n                \n                # Counter\n                passs = passs + 1\n     \n                \n                # Pass to the Level 3:\n                if (passs &gt;= 100):                    \n                    hoven = 1  \n            \n            \n            \n            \n            if (count &lt;= 2500) and (hoven == 1):\n            \n                # Body\n                cv2.line(img, (100, 250), (200, 260), (19,69,139), thickness = 110)\n                \n                # Barret:\n                cv2.circle(img,(102, 195), 25, (0,0,250), cv2.FILLED)\n            \n                # Face \n                cv2.circle(img,(100, 250), 55, (135,184,222), cv2.FILLED)\n            \n                # Nouse\n                cv2.circle(img,(100, 250), 5, (19,69,139), cv2.FILLED)\n                # Ulls:\n                cv2.circle(img,(115, 230), 8, (255,255,255), cv2.FILLED)\n                cv2.circle(img,(85, 230), 8, (255,255,255), cv2.FILLED)\n                cv2.circle(img,(115, 230), 2, (0,0,0), cv2.FILLED)\n                cv2.circle(img,(85, 230), 2, (0,0,0), cv2.FILLED)\n            \n                # Patas:\n                cv2.line(img, (165, 345), (130, 295), (19,69,139), thickness = 9)            \n                cv2.line(img, (35, 345), (70, 295), (19,69,139), thickness = 9)\n                \n                # Barret:\n                cv2.line(img, (80, 195), (125, 195), (0,0,0), thickness = 9)  \n            \n              \n                # Detect hand and get the poistion to print stick:\n                if (id == 20):\n                \n                    # Position of the stick and position to print the stick:\n                    stick_x = cx - 75\n                    stick_y = cy - 100\n                \n                    #Print stick:\n                    cv2.line(img, (cx, cy), (stick_x, stick_y), (45,82,160), thickness = 10)\n            \n            \n           \n                # DEtect if the stick is touching the Caga ti\u00f3.\n                if (stick_x &gt; 80) and (stick_x &lt; 220) and (stick_y &gt; 200 ) and (stick_y &lt; 305):\n                    \n                    # Count if is touching the tio.\n                    count = count + 1 \n                    #cv2.putText(img, str(int(count)), (100,40), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,0), 3)\n                \n                    # Write ouch if it touch it:\n                    cv2.putText(img, \"OUCH!!!!\", (150, 150), cv2.FONT_HERSHEY_PLAIN, 3, (0,0,255), 3)\n               \n            \n            \n            #Display where are the presents:\n            if (count &gt; 2500):\n                \n                cv2.putText(img, \"The caga Tio has pooped!!\", (40, 150), cv2.FONT_HERSHEY_PLAIN, 2, (0,0,0), 3)                #time.sleep(30)\n                \n                cv2.putText(img, \"Where are the presents??\", (40, 250), cv2.FONT_HERSHEY_PLAIN, 2, (0,0,0), 3)\n                \n                cv2.putText(img, location_presents, (40, 350), cv2.FONT_HERSHEY_PLAIN, 2, (0,0,0), 3)\n                \n            \n                # Get the x and y cor every second\n            s = time.strftime(\"%S\")\n            s = int(s)         \n                           \n    \n    cv2.imshow(\"Caga ti\u00f3\", img)\n    \n    # Press esc to close the windows\n    key = cv2.waitKey(1)    \n    if key == 27:\n        break\n        \ncap.release()\ncv2.destroyAllWindows()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Caga ti\u00f3 is a character in Catalan mythology relating to a Christmas tradition widespread in Catalonia. Created to expand the Catalan tradition without the need of traveling with a huge tronc in a plane\/car, this code created a virtual reality caga ti\u00f3. The program uses the cv2 library that does motion tracking. Detecting the different &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rodamoya.com\/index.php\/2023\/05\/02\/caga-tio\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> &#8220;<strong>Caga tio:<\/strong>&#8220;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/403"}],"collection":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":8,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"predecessor-version":[{"id":561,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/403\/revisions\/561"}],"wp:attachment":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}