{"id":547,"date":"2011-03-20T12:45:32","date_gmt":"2011-03-20T17:45:32","guid":{"rendered":"http:\/\/nootropicdesign.com\/projectlab\/?p=547"},"modified":"2019-05-26T11:22:58","modified_gmt":"2019-05-26T16:22:58","slug":"text-and-graphics-overlay","status":"publish","type":"post","link":"https:\/\/nootropicdesign.com\/projectlab\/2011\/03\/20\/text-and-graphics-overlay\/","title":{"rendered":"Text and Graphics Overlay on Video"},"content":{"rendered":"<p><strong><em>Difficulty Level = 2<\/em><\/strong>  <a href=\"\/projectlab\/difficulty-levels\/\">[What&#8217;s this?]<\/a><\/p>\n<p>The <a href=\"\/ve\">Video Experimenter<\/a> shield makes it easy to overlay text and graphics onto any composite video signal.  Any source of composite video should work &#8212; video camera, VCR, DVD player, DVR, cable box, etc.<\/p>\n<p><div id=\"attachment_618\" style=\"width: 650px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/overlayDemo.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-618\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/overlayDemo.jpg\" alt=\"\" title=\"overlayDemo\" width=\"640\" height=\"480\" class=\"size-full wp-image-618\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/overlayDemo.jpg 640w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2011\/03\/overlayDemo-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><p id=\"caption-attachment-618\" class=\"wp-caption-text\">Text and graphics overlayed onto a TV signal.<\/p><\/div><br \/>\n<br clear=\"all\"\/><\/p>\n<p>Video Experimenter projects require an <a target=\"_blank\" href=\"https:\/\/github.com\/nootropicdesign\/arduino-tvout-ve\" rel=\"noopener noreferrer\">enhanced version of the TVout library which can be downloaded here<\/a>.  All of the usual <a href=\"https:\/\/code.google.com\/archive\/p\/arduino-tvout\/wikis\">TVout drawing primitives<\/a> can be used to add text or graphics to the screen.  Here&#8217;s a video of a demo where I had the output of a VCR connected to the Video Experimenter input, then the Video Experimenter output connected to my TV.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/N2NPpFI18FM\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p\/>&nbsp;<br \/>\nThe OverlayDemo sketch is in the TVout examples folder.<\/p>\n<p>Here&#8217;s the OverlayDemo sketch source 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\r\n#define W 136\r\n#define H 96\r\n\r\nTVout tv;\r\nunsigned char x,y;\r\nunsigned char originx = 5;\r\nunsigned char originy = 80;\r\nunsigned char plotx = originx;\r\nunsigned char ploty = 40;\r\nchar s[32];\r\nint index = 0;\r\nint messageLen = 32;\r\nchar message[] = \"...OVERLAY TEXT AND GRAPHICS ON A VIDEO SIGNAL...OVERLAY TEXT AND GRAPHICS ON A VIDEO SIGNAL\";\r\nchar saveChar;\r\nbyte ledState = LOW;\r\n\r\nvoid setup()  {\r\n  tv.begin(NTSC, W, H);\r\n  initOverlay();\r\n  tv.select_font(font6x8);\r\n  tv.fill(0);\r\n  drawGraph();\r\n  randomSeed(analogRead(0));\r\n}\r\n\r\n\/\/ Initialize ATMega registers for video overlay capability.\r\n\/\/ Must be called after tv.begin().\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\n\/\/ Required to reset the scan line when the vertical sync occurs\r\nISR(INT0_vect) {\r\n  display.scanLine = 0;\r\n}\r\n\r\n\r\nvoid loop() {\r\n  saveChar = message[index+22];\r\n  message[index+22] = '\\0';\r\n\r\n  for(int x=6;x>=0;x--) {\r\n    if (x<6) {\r\n      tv.delay_frame(1);\r\n    } \r\n    tv.print(x, 87, message+index);\r\n\r\n    for(byte y=87;y<96;y++) {\r\n      tv.draw_line(0, y, 5, y, 0);\r\n      tv.draw_line(128, y, 134, y, 0);\r\n    }\r\n\r\n  }\r\n\r\n  message[index+22] = saveChar;\r\n  index++;\r\n  if (index > 45) {\r\n    index = 0;\r\n  }\r\n\r\n  sprintf(s, \"%ums\", millis());\r\n  tv.print(0, 0, s);\r\n\r\n\r\n  if (plotx++ > 120) {\r\n    tv.fill(0);\r\n    drawGraph();\r\n    plotx = originx + 1;\r\n    return;\r\n  }\r\n  byte newploty = ploty + random(0, 7) - 3;\r\n  newploty = constrain(newploty, 15, originy);\r\n  tv.draw_line(plotx-1, ploty, plotx, newploty, 1);\r\n  ploty = newploty;\r\n}\r\n\r\n\r\nvoid drawGraph() {\r\n  tv.draw_line(originx, 15, originx, originy, 1);\r\n  tv.draw_line(originx, originy, 120, originy, 1);\r\n  for(byte y=originy;y>15;y -= 4) {\r\n    tv.set_pixel(originx-1, y, 1);\r\n    tv.set_pixel(originx-2, y, 1);\r\n  }\r\n  for(byte x=originx;x<120;x += 4) {\r\n    tv.set_pixel(x, originy+1, 1);\r\n    tv.set_pixel(x, originy+2, 1);\r\n  }\r\n}\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Difficulty Level = 2 [What&#8217;s this?] The Video Experimenter shield makes it easy to overlay text and graphics onto any composite video signal. Any source of composite video should work &#8212; video camera, VCR, DVD player, DVR, cable box, etc. Video Experimenter projects require an enhanced version of the TVout library which can be downloaded [&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-547","post","type-post","status-publish","format-standard","hentry","category-arduino","category-video"],"_links":{"self":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/547","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=547"}],"version-history":[{"count":27,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/547\/revisions"}],"predecessor-version":[{"id":2280,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/547\/revisions\/2280"}],"wp:attachment":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/media?parent=547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/categories?post=547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/tags?post=547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}