{"id":491,"date":"2019-07-01T12:00:34","date_gmt":"2019-07-01T19:00:34","guid":{"rendered":"http:\/\/letsbuildroboticswithshadow8472.com\/?p=491"},"modified":"2019-06-30T18:46:04","modified_gmt":"2019-07-01T01:46:04","slug":"programming-a-pi-to-deter-cats-part-6","status":"publish","type":"post","link":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2019\/07\/01\/programming-a-pi-to-deter-cats-part-6\/","title":{"rendered":"Programming a Pi to Deter Cats: Part 6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Good Morning from my Robotics Lab! This is Shadow_8472, and today, I&#8217;m working on my Raspberry Pi again to make it chase cats off counters. Let&#8217;s get started.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A lot has happened this week, yet it feels like not enough. I had a Python script running OpenCV from the command line last week, and this week, I&#8217;ve started work on the dynamic background.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;d have to say I&#8217;m not quite a third of the way to this smaller goal, but in terms of required research, I should be finished with it next week. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Right now, I have the pseudocode for this part of the project, as well as a demo highlighting the difference between the last two frames. To get to that point, I had to buffer frames to a two-frame queue, then compare them. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is not fun when you have an error search engines don&#8217;t recognize. &#8220;Src1 is not a valid numerical tuple.&#8221; Long story short, it was the way Python arrays work. They need to be declared, then each element, or a placeholder element added. Somehow, after giving up for the night, I halfheartedly tinkered with swapping the order of comparison, and it followed the same element. I traced the bug back through my IO function, and got a buffered video feed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The other exciting thing was finding the comparison function. The buffer has a pointer to say which is the more recent frame, and reading the most recent frame is fine, but the trick here is to highlight what&#8217;s new and changed this frame. It took a bit to find that function, and I played with a few bitwise operators I found next to it. One strangely affected the &#8220;raw footage,&#8221; and ended up strobing. I had to slow the framerate on that one to see it was inverting everything each frame.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The very next thing to do is to boost those frames to all white, but I haven&#8217;t found how to do that yet. After that, I need to figure out how to extract the resolution and get the demo working in low resolution mode by scaling the width and height down by an integer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a scaled down resolution, I should be able to build a heatmap as a countdown timer until areas fade into the background. Once I have all that working, I can start researching again for spawning a second thread and analysing the full resolution picture for naughty felines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Final Question: How many more weekly parts should it take before I have my first working prototype?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good Morning from my Robotics Lab! This is Shadow_8472, and today, I&#8217;m working on my Raspberry Pi again to make it chase cats off counters. Let&#8217;s get started. A lot has happened this week, yet it feels like not enough. I had a Python script running OpenCV from the command line last week, and this &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2019\/07\/01\/programming-a-pi-to-deter-cats-part-6\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Programming a Pi to Deter Cats: Part 6&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":1,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions\/492"}],"wp:attachment":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}