{"id":736,"date":"2016-08-22T06:01:29","date_gmt":"2016-08-22T04:01:29","guid":{"rendered":"https:\/\/www.kurokesu.com\/main\/?p=736"},"modified":"2016-09-01T20:24:58","modified_gmt":"2016-09-01T18:24:58","slug":"unusual-tasks-with-video-files-reading-bar-codes-and-qr-codes","status":"publish","type":"post","link":"https:\/\/www.kurokesu.com\/main\/2016\/08\/22\/unusual-tasks-with-video-files-reading-bar-codes-and-qr-codes\/","title":{"rendered":"Unusual tasks with video files &#8211; reading bar-codes and qr-codes"},"content":{"rendered":"<p style=\"text-align: justify;\"><a href=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-857 size-medium\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r-300x251.jpg\" alt=\"IMG_1450_2r\" width=\"300\" height=\"251\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r-300x251.jpg 300w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r-768x643.jpg 768w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r-1024x857.jpg 1024w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r.jpg 1500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>A barcode is an optical, machine-readable, representation of data; the data usually describes something about the object that carries the barcode &#8211; <a href=\"https:\/\/en.wikipedia.org\/wiki\/Barcode\">wikipedia<\/a>. While first barcode was patented on 1952, it took quite a while until these codes were used in first grocery store on 1974. And now they are being used everywhere.<\/p>\n<p style=\"text-align: justify;\">While using them looks quite obvious for countless people on a daily basis, science behind making and reading is much more complicated. I will skip this hi-tech theory and jump directly to examples how to generate and decode them using some clever Python scripts and a <a href=\"http:\/\/www.kurokesu.com\/shop\/cameras\/CAMUSB1\">Kurokesu C1 USB camera<\/a> connected to computer.<\/p>\n<h3>Generating barcodes<\/h3>\n<p>I will be using <a href=\"https:\/\/pypi.python.org\/pypi\/viivakoodi\/\">viivakoodi<\/a> python library to generate barcodes (others like OpenCV and numpy are required, so install them before use). While there are few similar python libraries, viivakoodi supports generating CODE128 barcodes.<\/p>\n<pre>pip install viivakoodi<\/pre>\n<p style=\"text-align: justify;\">Native\u00a0viivakoodi output format is SVG but I needed PNG. Quick format conversion and output file is a nice raster file.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/Lukse\/a8afa42219fe8cf641f3c7b8c60e9338.js\"><\/script><\/p>\n<div id=\"attachment_846\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-846\" class=\"wp-image-846\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/code-1024x364.png\" alt=\"code\" width=\"300\" height=\"107\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/code-1024x364.png 1024w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/code-300x107.png 300w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/code-768x273.png 768w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/code.png 1902w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-846\" class=\"wp-caption-text\">Generated CODE-128 barcode<\/p><\/div>\n<p style=\"text-align: justify;\">This library also can output barcode in various other formats: code128, code39, ean, ean13, ean8, gs1, gtin, isbn, isbn10, isbn13, issn, jan, pzn, upc, upca. Some barcodes can&#8217;t encode letters, some have other creation rules. Usually library this let&#8217;s know what is happening and gives you a hint. Also worth to be noted that CODE-128 has checksum fields and this library calculates it just fine.<\/p>\n<h3>Generating QRcodes<\/h3>\n<p>QRcode is more advanced barcode version. Information is encoded in 2D format.<\/p>\n<pre>pip install qrcode<\/pre>\n<p>These barcodes being two dimensional allow more information to be encoded. Also has flexibility to control how much redundant information to be used.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/Lukse\/2d3dc8e6698ac5a6c4a12769ef6f2348.js\"><\/script><\/p>\n<div id=\"attachment_852\" style=\"width: 210px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-852\" class=\"wp-image-852\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/qr.png\" alt=\"qr\" width=\"200\" height=\"200\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/qr.png 540w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/qr-150x150.png 150w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/qr-300x300.png 300w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><p id=\"caption-attachment-852\" class=\"wp-caption-text\">Generated QRcode<\/p><\/div>\n<h3>Barcode and Qrcode recognition<\/h3>\n<p style=\"text-align: justify;\">Luckily there is single library to recognize barcodes and qrcodes. It&#8217;s called <a href=\"http:\/\/zbar.sourceforge.net\/\">zbar<\/a>. Let&#8217;s prepare some barbodes for automated recognition and run zbar script. While Zbar was last modified on 2011, it is still the best open-sources recognition software. It might require some tricks installing it but it is definitely worth trying. Zbar supports following barcode formats: EAN-13\/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR Code<\/p>\n<div id=\"attachment_854\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-854\" class=\"wp-image-854\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/barcodes-e1471770618905.png\" alt=\"barcodes\" width=\"500\" height=\"403\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/barcodes-e1471770618905.png 832w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/barcodes-e1471770618905-300x242.png 300w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/barcodes-e1471770618905-768x618.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><p id=\"caption-attachment-854\" class=\"wp-caption-text\">Sheet of paper with some barcodes and qrcodes<\/p><\/div>\n<p><script src=\"https:\/\/gist.github.com\/Lukse\/29cafd7d980b94f8e791bc0a7a6ffb5a.js\"><\/script><\/p>\n<p>Results are more than satisfying. I got ~10fps recognition speed on modern computer. Video source was 1080&#215;1080. Some barcodes were not recognized &#8211; they were to small or unsupported format.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_859\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-859\" class=\"wp-image-859 size-full\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/out-1.gif\" alt=\"out\" width=\"500\" height=\"281\" \/><p id=\"caption-attachment-859\" class=\"wp-caption-text\">Zbar recognition results<\/p><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A barcode is an optical, machine-readable, representation of data; the data usually describes something about the object that carries the barcode &#8211; wikipedia. While first barcode was patented on 1952, it took quite a while until these codes were used in first grocery store on 1974. And now they are being used everywhere. While using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":857,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[153],"tags":[114,119,120,117,49,115,116,121,122,118],"class_list":["post-736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","tag-barcode","tag-code128","tag-ean","tag-generate","tag-python","tag-qrrcode","tag-read","tag-upc","tag-viivakoodi","tag-zbar"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2016\/08\/IMG_1450_2r.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6VSmB-bS","_links":{"self":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":36,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/736\/revisions\/878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/media\/857"}],"wp:attachment":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}