{"id":2557,"date":"2020-01-16T16:10:30","date_gmt":"2020-01-16T16:10:30","guid":{"rendered":"http:\/\/www.bardecode.com\/newsite\/?p=2557"},"modified":"2020-01-17T10:15:20","modified_gmt":"2020-01-17T10:15:20","slug":"using-opencv-images-softek-barcode-reader-toolkit","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/newsite\/using-opencv-images-softek-barcode-reader-toolkit\/","title":{"rendered":"Using opencv images with the Softek barcode reader toolkit"},"content":{"rendered":"<p>Here&#8217;s some C code that shows how to read an opencv cv::Mat image using the barcode reader toolkit. The main points to note are:<\/p>\n<ul>\n<li>Read the image using the cv::IMREAD_GRAYSCALE flag<\/li>\n<li>Flip the image vertically<\/li>\n<li>Align the scan lines to 4 byte boundaries<\/li>\n<\/ul>\n<p>#include &lt;barcode.h&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;opencv2\/core\/core.hpp&gt;<br \/>\n#include &lt;opencv2\/highgui\/highgui.hpp&gt;<br \/>\n#include &lt;opencv2\/imgproc\/imgproc.hpp&gt;<\/p>\n<p>static void convertBitmapData(unsigned char *in, BITMAP *pBm)<br \/>\n{<br \/>\nint y ;<br \/>\nunsigned char *out;<\/p>\n<p>out = (unsigned char *) pBm-&gt;bmBits + (pBm-&gt;bmWidthBytes * pBm-&gt;bmHeight);<\/p>\n<p>for (y = 0; y &lt; pBm-&gt;bmHeight; y++)<br \/>\n{<br \/>\nout -= pBm-&gt;bmWidthBytes;<br \/>\nmemcpy(out, in, pBm-&gt;bmWidth);<br \/>\nin += pBm-&gt;bmWidth;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>main()<br \/>\n{<br \/>\nint i ;<br \/>\nint n ;<br \/>\nBITMAP bm ;<br \/>\nchar **bar_codes ;<br \/>\nchar **bar_codes_type ;<br \/>\nvoid *hBarcode ;<\/p>\n<p>cv::Mat img = cv::imread(&#8220;somefile.tif&#8221;, cv::IMREAD_GRAYSCALE);<\/p>\n<p>bm.bmWidth = img.size().width;<br \/>\nbm.bmHeight = img.size().height;<br \/>\nbm.bmBitsPixel = 8; \/\/ from IMREAD_GRAYSCALE<br \/>\nbm.bmWidthBytes = bm.bmWidth ;<br \/>\nif (bm.bmWidthBytes % 4) bm.bmWidthBytes += 4 &#8211; (bm.bmWidthBytes % 4); \/\/ Pad to 4 byte boundary<br \/>\nbm.bmPlanes = 1;<br \/>\nbm.bmType = 1;<br \/>\nbm.bmBits = (void *) malloc (bm.bmWidthBytes * bm.bmHeight);<\/p>\n<p>convertBitmapData((unsigned char *) img.data, &amp;bm);<\/p>\n<p>hBarcode = STCreateBarCodeSession() ;<\/p>\n<p>n = STReadBarCodeFromBitmap(hBarcode, &amp;bm, (float) 200, &amp;bar_codes, &amp;bar_codes_type, 0) ;<\/p>\n<p>for (i = 0; i &lt; n; i++)<br \/>\nstd::cout &lt;&lt; bar_codes[i] &lt;&lt; std::endl;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s some C code that shows how to read an opencv cv::Mat image using the barcode reader toolkit. The main points to note are: Read the image using the cv::IMREAD_GRAYSCALE flag Flip the image vertically Align the scan lines to 4 byte boundaries #include &lt;barcode.h&gt; #include &lt;iostream&gt; #include &lt;opencv2\/core\/core.hpp&gt; #include &lt;opencv2\/highgui\/highgui.hpp&gt; #include &lt;opencv2\/imgproc\/imgproc.hpp&gt; static void &hellip; <\/p>\n","protected":false},"author":1,"featured_media":324,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236,18,203,31],"tags":[],"class_list":["post-2557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation-for-our-toolkits-and-applications","category-knowledge-base","category-news","category-software-development-kits"],"_links":{"self":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2557"}],"collection":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/comments?post=2557"}],"version-history":[{"count":5,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2557\/revisions"}],"predecessor-version":[{"id":2562,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2557\/revisions\/2562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/media\/324"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/media?parent=2557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/categories?post=2557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/tags?post=2557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}