{"id":551,"date":"2011-03-20T14:52:05","date_gmt":"2011-03-20T19:52:05","guid":{"rendered":"http:\/\/nootropicdesign.com\/projectlab\/?p=551"},"modified":"2018-11-02T09:08:42","modified_gmt":"2018-11-02T14:08:42","slug":"video-frame-capture","status":"publish","type":"post","link":"https:\/\/nootropicdesign.com\/projectlab\/2011\/03\/20\/video-frame-capture\/","title":{"rendered":"Video Frame Capture using the Video Experimenter Shield"},"content":{"rendered":"<p><strong><em>Difficulty Level = 3<\/em><\/strong>  <a href=\"\/projectlab\/difficulty-levels\/\">[What&#8217;s this?]<\/a><\/p>\n<p>In addition to overlaying text and graphics onto a video signal, the <a href=\"\/ve\">Video Experimenter<\/a> shield can also be used to capture image data from a video source and store it in the Arduino&#8217;s SRAM memory. The image data can be displayed to a TV screen and can be overlayed onto the original video signal.<\/p>\n<p>Believe it or not, the main loop of the program is this simple:<\/p>\n<pre class=\"codeblock\">\r\nvoid loop() {\r\n  tv.capture();\r\n  tv.resume();\r\n  tv.delay_frame(5);\r\n}\r\n<\/pre>\n<p><strong>NOTE: <\/strong>On versions of Arduino greater than 1.6, you may need to add a 1ms delay at the end of loop. Just the line &#8220;delay(1);&#8221;.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/lfGNqX3nzFs?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p\/>&nbsp;<br \/>\nFor this project, we connect a video camera to the input of the Video Experimenter shield.  The output select switch is set to &#8220;overlay&#8221; and the sync select jumper is set to &#8220;video input&#8221;.  The video output is connected to an ordinary TV.  When performing this experiment, turn the analog threshold potentiometer to the lowest value to start, then adjust it to select different brightness thresholds when capturing images.<\/p>\n<p>By moving the output select switch to &#8220;sync only&#8221;, the original video source is not included in the output, only the captured monochrome image.  You will need to adjust the threshold potentiometer (the one with the long shaft) to a higher value when the output switch is in this position.  Experiment!<\/p>\n<p><div id=\"attachment_642\" style=\"width: 490px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/videoFrameCapture.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-642\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/videoFrameCapture.jpg\" alt=\"\" title=\"videoFrameCapture\" width=\"480\" height=\"360\" class=\"size-full wp-image-642\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/videoFrameCapture.jpg 480w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/videoFrameCapture-300x225.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-642\" class=\"wp-caption-text\">Monochrome video frame capture in Arduino memory<\/p><\/div><br \/>\n<br clear=\"all\"\/><br \/>\nIn the <span class=\"code\">VideoFrameCapture.ino<\/span> sketch below, we capture the image in memory by calling <span class=\"code\">tv.capture()<\/span>.  When this method returns, a monochrome image is stored in the TVout frame buffer.  The contents of the frame buffer are not displayed until we call <span class=\"code\">tv.resume()<\/span>.  This project is the example &#8220;VideoFrameCapture&#8221; in the <a target=\"_blank\" href=\"https:\/\/github.com\/nootropicdesign\/arduino-tvout-ve\">TVout library for Video Experimenter<\/a>. <\/p>\n<p>Here is the Arduino code.  If you use a television with the PAL standard (that is, you are not in North America), change <span class=\"code\">tv.begin(NTSC, W, H)<\/span> to <span class=\"code\">tv.begin(PAL, W, H)<\/span>.<\/p>\n<pre class=\"codeblockscroll\">\r\n#include &lt;TVout.h&gt;\r\n#include &lt;fontALL.h&gt;\r\n#define W 128\r\n#define H 96\r\n\r\nTVout tv;\r\nunsigned char x,y;\r\nchar s[32];\r\n\r\n\r\nvoid setup()  {\r\n  tv.begin(NTSC, W, H);\r\n  initOverlay();\r\n  initInputProcessing();\r\n\r\n  tv.select_font(font4x6);\r\n  tv.fill(0);\r\n}\r\n\r\n\r\nvoid initOverlay() {\r\n  TCCR1A = 0;\r\n  \/\/ Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.\r\n  TCCR1B = _BV(CS10);\r\n\r\n  \/\/ Enable input capture interrupt\r\n  TIMSK1 |= _BV(ICIE1);\r\n\r\n  \/\/ Enable external interrupt INT0 on pin 2 with falling edge.\r\n  EIMSK = _BV(INT0);\r\n  EICRA = _BV(ISC01);\r\n}\r\n\r\nvoid initInputProcessing() {\r\n  \/\/ Analog Comparator setup\r\n  ADCSRA &= ~_BV(ADEN); \/\/ disable ADC\r\n  ADCSRB |= _BV(ACME); \/\/ enable ADC multiplexer\r\n  ADMUX &= ~_BV(MUX0);  \/\/ select A2 for use as AIN1 (negative voltage of comparator)\r\n  ADMUX |= _BV(MUX1);\r\n  ADMUX &= ~_BV(MUX2);\r\n  ACSR &= ~_BV(ACIE);  \/\/ disable analog comparator interrupts\r\n  ACSR &= ~_BV(ACIC);  \/\/ disable analog comparator input capture\r\n}\r\n\r\nISR(INT0_vect) {\r\n  display.scanLine = 0;\r\n}\r\n\r\nvoid loop() {\r\n  tv.capture();\r\n  \/\/tv.fill(INVERT);\r\n  tv.resume();\r\n  tv.delay_frame(5);\r\n  delay(1);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Difficulty Level = 3 [What&#8217;s this?] In addition to overlaying text and graphics onto a video signal, the Video Experimenter shield can also be used to capture image data from a video source and store it in the Arduino&#8217;s SRAM memory. The image data can be displayed to a TV screen and can be overlayed [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[3,26],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-arduino","category-video"],"_links":{"self":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":32,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":1954,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/551\/revisions\/1954"}],"wp:attachment":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}