{"id":1826,"date":"2015-03-13T00:00:51","date_gmt":"2015-03-13T07:00:51","guid":{"rendered":"http:\/\/192.168.3.4\/?p=1826"},"modified":"2018-01-09T06:49:48","modified_gmt":"2018-01-09T14:49:48","slug":"tft-lcd-and-nearir-camera-modules-on-the-rpi","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=1826","title":{"rendered":"SimpleCV on the RPi"},"content":{"rendered":"<p><strong>Introduction &#8211; keep your eye on the ball<br \/>\n<\/strong><\/p>\n<p>What is CV, or Computer Vision?\u00a0 A search online will give you a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Computer_vision\" target=\"_blank\">definition<\/a>, &#8220;Computer vision is a field that includes methods for acquiring, processing, analyzing, and understanding images and, in general, high-dimensional data from the real world in order to produce numerical or symbolic information, e.g., in the forms of decisions&#8230;&#8221;<\/p>\n<p>Basically, it is using any image sensor to influence the action of a computer.\u00a0 There are some fundamental sensors that will provide this such as a <a href=\"https:\/\/www.adafruit.com\/product\/161\" target=\"_blank\">photo resistor<\/a> or <a href=\"https:\/\/www.sparkfun.com\/products\/242\" target=\"_blank\">IR proximity sensor<\/a>.\u00a0 I&#8217;ve used <a href=\"http:\/\/www.parallax.com\/product\/555-28027\" target=\"_blank\">these types<\/a> of vision sensors with micro controllers to trigger alarms and take action before.\u00a0 But CV is a bit more sophisticated than that.<\/p>\n<p>The RPi can do the fundamental light sensor tasks like its micro controller counter parts.\u00a0 However, it is more adapt at processing complex data from array sensors like camera modules and line scanners.\u00a0 This is were processing tools like OpenCV and Simple CV come into play.<\/p>\n<p><a href=\"http:\/\/opencv.org\/\" target=\"_blank\">OpenCV<\/a> was developed by Intel at their\u00a0Russian research facility in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Nizhny_Novgorod\" target=\"_blank\">Nizhny Novgorod<\/a>.\u00a0 Here is a video from Francesco Piscani detailing the install steps, of which I validated.<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/jvFM-gIGpQQ\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>The installation of OpenCV on the RPi is a time consuming effort, in contrast to SimpleCV.\u00a0 For this reason, I&#8217;ll be focusing my efforts on this post towards the SimpleCV development platform.<\/p>\n<p><a href=\"http:\/\/simplecv.org\/\" target=\"_blank\">SimpleCV<\/a> is the work of the team at <a href=\"http:\/\/sightmachine.com\/team\/\" target=\"_blank\">Sight Machine<\/a>.\u00a0 They specialize in manufacture automation using computer aided visual inspection systems.\u00a0 This <a href=\"http:\/\/www.wired.com\/2014\/01\/liberating-machine-vision-machines\/\" target=\"_blank\">article in Wired<\/a> shows why they are in <a href=\"http:\/\/venturebeat.com\/2015\/02\/09\/manufacturing-analytics-pioneer-sight-machine-announces-5-million-funding-led-by-mercury-fund\/\" target=\"_blank\">the business<\/a> of CV.<\/p>\n<p>The commonality of CV is taking images from camera sensors and processing the data to determine a logical state.\u00a0 This logical state can be used to determine a course of action.<\/p>\n<p><strong>Intent &#8211; eye of the beholder<br \/>\n<\/strong><\/p>\n<p>How can CV be used?\u00a0 Some of the more basic uses are for security and identification.\u00a0 There are numerous examples of face tracking, parking enforcement, or license plate identification online.\u00a0 One of the most clever uses I found online was a developer&#8217;s effort to keep his local bird population fed.<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/QPgqfnKG_T4\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><strong>Details &#8211; eye of the tiger<br \/>\n<\/strong><\/p>\n<p>Lets dive in and get SimpleCV installed.\u00a0 You can get the steps to do that <a href=\"http:\/\/simplecv.readthedocs.org\/en\/latest\/HOWTO-Install%20on%20RaspberryPi.html?highlight=opencv\" target=\"_blank\">here<\/a>.\u00a0 But I want to write them up as well in the event of changes.<\/p>\n<p>1. Run this command to install the core dependencies.<\/p>\n<pre><code>sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools python-pip<\/code><\/pre>\n<p>2. SimpleCV should now be ready to install. Download SimpleCV from github and install from the source.<\/p>\n<pre><code>sudo pip install https:\/\/github.com\/sightmachine\/SimpleCV\/zipball\/master<\/code><\/pre>\n<p>3. I found that I had to run one more dependency<\/p>\n<pre><code>sudo pip install svgwrite<\/code><\/pre>\n<p>4. SimpleCV should be all set up. Connect a compatible camera to the board\u2019s usb input and open up the simplecv shell by typing in this command.<\/p>\n<pre><code>simplecv<\/code><\/pre>\n<p>How simple was that!?\u00a0 Now we can move on to some examples, but before we do I would like to install the ability to play media files.\u00a0 We&#8217;ll install mplayer using this command.<\/p>\n<pre><code>sudo apt-get install mplayer<\/code><\/pre>\n<p>Once that is installed, you can verify it works using a sample video.\u00a0 I used the <a href=\"https:\/\/learn.adafruit.com\/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi\/playing-videos\" target=\"_blank\">one suggested by Adafruit<\/a> for the TFT demo.\u00a0 So on toward the examples.\u00a0 The first one I tried was the &#8220;<a href=\"http:\/\/tutorial.simplecv.org\/en\/latest\/examples\/helloworld.html\" target=\"_blank\">HelloWorld.py<\/a>&#8221; example that the SimpleCV folks provide online.\u00a0 If all goes well, you should see an image with the words &#8220;Hello World&#8221; in the upper left corner.\u00a0 On my instance, I noticed that the image was choppy and the color level of the camera was black and white.\u00a0 So I back tracked a bit and tried some earlier examples.<\/p>\n<p>My results were more of what I expected when ran inside the simplecv console, this is done by opening a terminal and entering &#8220;simplecv&#8221; at the prompt.\u00a0 Then you can enter in the following code.<\/p>\n<pre><code>SimpleCV:1&gt; cam = Camera()\r\nSimpleCV:1&gt; img = cam.getImage()\r\nSimpleCV:1&gt; img.show()\r\nSimpleCV:1&gt; img.save(\"\/home\/pi\/camcap.png\")\r\n<\/code><\/pre>\n<p>You can find this example and more on the <a href=\"http:\/\/tutorial.simplecv.org\/en\/latest\/examples\/basics.html\" target=\"_blank\">SimpleCV tutorial<\/a> site.<\/p>\n<p><strong>Relevance\u00a0&#8211; I&#8217;ll be watching you<br \/>\n<\/strong><\/p>\n<p>What can we do with CV?\u00a0 That answer is left to the imagination.\u00a0 I&#8217;ve seen several examples of traffic and security applications.\u00a0 It&#8217;s development into the SimpleCV package was brought about by a group interested in quality assurance applications.\u00a0 How would I apply this to my bike rides?\u00a0 I don&#8217;t know.\u00a0 One idea that plays into the theme of this years instruction is to use it for augmented reality.\u00a0 It&#8217;s possible for me to plot the conditions of a bike route, like surface conditions.\u00a0 Later I could reference the track data and be warned when I&#8217;m approaching them then next time through.\u00a0 At any rate, the ability to use the technology on a compact mobile system is possible.<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/1GhNXHCQGsM\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><br \/>\n<strong>Summary &#8211; watch the watch<br \/>\n<\/strong><\/p>\n<p>In this topic we covered the concepts of computer vision.\u00a0 I did an introduction to OpenCV as well as SimpleCV and some key differences.\u00a0 I then went through the procedures to installing SimpleCV on the RPi.\u00a0 From there we ran through a couple of examples to show that our install worked.\u00a0 Finally, I covered some applications of computer vision technology.<\/p>\n<p>This has been a basic introduction to the topic of computer vision.\u00a0 From here we can take the next step toward machine automation based on visual input from advanced sensor devices.<\/p>\n<p>There were a host of examples that I would like to list here.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=jihxqg3kr-g\" target=\"_blank\">SimpleCV Object (White Ball) tracker &#8211; 15 lines of code<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=wDAFhOv0tKU\" target=\"_blank\">Tracking colored cards using python and SimpleCV <\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=JM5ZkcW2gsM\" target=\"_blank\">SimpleCV Tutorial &#8211; Multiple Cameras <\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=icjEyZ605KQ\" target=\"_blank\">Simple Blue Circle Tracker<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=4Deypz8Bh-c\" target=\"_blank\">CAMShift Tracking with SimpleCV <\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=w3n9amf1cV0\" target=\"_blank\">Light tracking using the webcam (Python + SimpleCV) <\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=8SkdfdXWYaI\" target=\"_blank\">Using Python to Code by Voice <\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction &#8211; keep your eye on the ball What is CV, or Computer Vision?\u00a0 A search online will give you a definition, &#8220;Computer vision is a field that includes methods for acquiring, processing, analyzing, and understanding images and, in general, high-dimensional data from the real world in order to produce numerical or symbolic information, e.g., in the forms of decisions&#8230;&#8221; Basically, it is using any image sensor to influence the action of a computer.\u00a0 There are some fundamental sensors that&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=1826\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,6,3],"tags":[],"class_list":["post-1826","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1826"}],"version-history":[{"count":37,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1826\/revisions"}],"predecessor-version":[{"id":2321,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1826\/revisions\/2321"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}