{"id":1731,"date":"2011-08-24T14:56:01","date_gmt":"2011-08-24T21:56:01","guid":{"rendered":"http:\/\/mcclanahoochie.com\/blog\/?p=1731"},"modified":"2015-04-26T20:44:53","modified_gmt":"2015-04-27T03:44:53","slug":"image-processing-with-libjacket-opencv","status":"publish","type":"post","link":"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/image-processing-with-libjacket-opencv\/","title":{"rendered":"Image processing with LibJacket + OpenCV"},"content":{"rendered":"<p><em>Update: one year later:\u00a0<a href=\"http:\/\/mcclanahoochie.com\/blog\/portfolio\/local-contrast-enhancement-with-arrayfire-opencv\/\" target=\"_blank\">ArrayFire+OpenCV<\/a><\/em><\/p>\n<p>The <a href=\"http:\/\/opencv.org\/\" target=\"_blank\">OpenCV<\/a> library is the de-facto standard for doing computer vision and image processing research projects. OpenCV includes several hundreds of computer vision algorithms, aimed for use in real-time vision applications.<\/p>\n<p><a href=\"http:\/\/web.archive.org\/web\/20110707080428\/http:\/\/wiki.accelereyes.com\/wiki\/libjacket\/\" target=\"_blank\">LibJacket<\/a> is a matrix library built on CUDA. LibJacket offers hundreds of general matrix and image processing functions, all running on the GPU. The syntax is very high level and easy to use.<\/p>\n<h2>LibJacket with OpenCV<\/h2>\n<p>For anyone out there interested in using both libraries together <em>(ie. wanting parts of their code to run faster on a GPU very easily),<\/em> I have put together a simple example application that demonstrates using OpenCV&#8217;s for webcam access and LibJacket for some basic processing routines and displaying results.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1735\" data-permalink=\"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/image-processing-with-libjacket-opencv\/screen-shot-2011-08-24-at-2-42-52-pm\/#main\" data-orig-file=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?fit=1680%2C1050&amp;ssl=1\" data-orig-size=\"1680,1050\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Screen shot 2011-08-24 at 2.42.52 PM\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?fit=1024%2C640&amp;ssl=1\" class=\"aligncenter size-large wp-image-1735\" title=\"Screen shot 2011-08-24 at 2.42.52 PM\" src=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM-1024x640.png?resize=584%2C365\" alt=\"\" width=\"584\" height=\"365\" srcset=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?resize=480%2C300&amp;ssl=1 480w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.42.52-PM.png?w=1680&amp;ssl=1 1680w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>[ Linux\/Mac Only ]<br \/>\nTo run this example, simply download the source code (webcam_demo.cpp) and Makefile <a href=\"http:\/\/code.google.com\/p\/mcclanahoochie\/source\/browse\/cuda\/cam-libjacket\/\" target=\"_blank\">HERE<\/a>, and place them in your libjacket\/examples\/image\/ directory, and type:<br \/>\n<code> make &amp;&amp; .\/webcam_demo<\/code><br \/>\nYou must have a copy of LibJacket and OpenCV installed first, of course!<\/p>\n<h1>Sample code<\/h1>\n<p>Excerpt code snippit from <a href=\"http:\/\/code.google.com\/p\/mcclanahoochie\/source\/browse\/cuda\/cam-libjacket\/webcam_demo.cpp\" target=\"_blank\">webcam_demo.cpp<\/a>:<br \/>\n<code><br \/>\n\/\/ extract cv image<br \/>\nMat mgray (img.rows, img.cols, CV_8UC1);<br \/>\ncvtColor(img.t(), mgray, CV_BGR2GRAY);<br \/>\nmgray.convertTo(mgray, CV_32FC1);<br \/>\nfloat* fgray = (float*)mgray.data;<\/code><br \/>\n<code><br \/>\n\/\/ copy to gpu<br \/>\nf32 I1 = f32(fgray, img.rows, img.cols);<\/code><br \/>\n<code><br \/>\n\/\/ display window<br \/>\nfigure(); colormap(\"gray\");<br \/>\nsubplot(3, 3, 1); imagesc(I1); title(\"source image\");<\/code><br \/>\n<code><br \/>\n\/\/ process<br \/>\n...<br \/>\n...<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1745\" data-permalink=\"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/image-processing-with-libjacket-opencv\/screen-shot-2011-08-24-at-2-40-02-pm\/#main\" data-orig-file=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?fit=1680%2C1050&amp;ssl=1\" data-orig-size=\"1680,1050\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Screen shot 2011-08-24 at 2.40.02 PM\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?fit=1024%2C640&amp;ssl=1\" class=\"aligncenter size-large wp-image-1745\" title=\"Screen shot 2011-08-24 at 2.40.02 PM\" src=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM-1024x640.png?resize=584%2C365\" alt=\"\" width=\"584\" height=\"365\" srcset=\"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?resize=480%2C300&amp;ssl=1 480w, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/Screen-shot-2011-08-24-at-2.40.02-PM.png?w=1680&amp;ssl=1 1680w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>New Example!: <a href=\"http:\/\/mcclanahoochie.com\/blog\/portfolio\/gpu-tv-l1-optical-flow-with-libjacket\/\" target=\"_blank\">TV-L1 optical flow using LibJacket!<\/a><\/p>\n<p><em>Update: one year later:\u00a0<a href=\"http:\/\/mcclanahoochie.com\/blog\/portfolio\/local-contrast-enhancement-with-arrayfire-opencv\/\" target=\"_blank\">ArrayFire+OpenCV<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: one year later:\u00a0ArrayFire+OpenCV The OpenCV library is the de-facto standard for doing computer vision and image processing research projects. OpenCV includes several hundreds of computer vision algorithms, aimed for use in real-time vision applications. LibJacket is a matrix library built on CUDA. LibJacket offers hundreds of general matrix and image processing functions, all running &#8230; <a title=\"Image processing with LibJacket + OpenCV\" class=\"read-more\" href=\"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/image-processing-with-libjacket-opencv\/\" aria-label=\"Read more about Image processing with LibJacket + OpenCV\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"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":[1],"tags":[91,113,54,92],"class_list":["post-1731","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arrayfire","tag-computer-vision","tag-image-processing","tag-opencv"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pZdXI-rV","jetpack-related-posts":[{"id":1896,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/11\/gpu-tv-l1-optical-flow-with-libjacket\/","url_meta":{"origin":1731,"position":0},"title":"GPU TV-L1 Optical Flow with ArrayFire","author":"mcclanahoochie","date":"November 6, 2011","format":false,"excerpt":"Update 1: LibJacket has been renamed to\u00a0\u00a0ArrayFire. Update 2: Huang Chao-Hui was nice enough to port the LibJacket code mentioned here to ArrayFire - see his work here. As one of my\u00a0Computer Vision\u00a0class\u00a0projects, I decided to implement optical flow, because I wanted to learn more about optical flow, and also\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/11\/jkt-oflow-tvl1-1024x626.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/11\/jkt-oflow-tvl1-1024x626.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/11\/jkt-oflow-tvl1-1024x626.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1810,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/09\/opencv-vs-libjacket-gpu-sobel-filtering\/","url_meta":{"origin":1731,"position":1},"title":"OpenCV vs. LibJacket: GPU Sobel Filtering","author":"mcclanahoochie","date":"September 24, 2011","format":false,"excerpt":"Update: LibJacket has been renamed to\u00a0\u00a0ArrayFire. In response to a comment on a previous post about integrating LibJacket into an OpenCV project, below is just a simple FYI performance comparison of OpenCV's GPU Sobel filter versus LibJacket's conv2\u00a0convolution\u00a0filter (with a sobel kernel)... This is an evolutionary post, so be sure\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"Sobel filter: OpenCV GPU vs. LibJacket","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/09\/cv-versus-jkt.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1876,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/10\/gpu-convolution-opencv-gpu-and-libjacket-part-2\/","url_meta":{"origin":1731,"position":2},"title":"GPU Convolutions: OpenCV GPU and LibJacket &#8211; Part 2","author":"mcclanahoochie","date":"October 24, 2011","format":false,"excerpt":"This is a response to my earlier post comparing OpenCV's gpu::convolve() and LibJacket's jkt::conv2() convolution functions, at various image and kernel sizes. That post generated a lot of traffic, most notably from the OpenCV developer community. Taking note of this, it seems that the folks at Willow Garage have re-vamped\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":".","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/10\/Screenshot-f2-2075.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/10\/Screenshot-f2-2075.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/10\/Screenshot-f2-2075.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2347,"url":"https:\/\/mcclanahoochie.com\/blog\/2012\/08\/local-contrast-enhancement-with-arrayfire-opencv\/","url_meta":{"origin":1731,"position":3},"title":"Local Contrast Enhancement with ArrayFire + OpenCV","author":"mcclanahoochie","date":"August 20, 2012","format":false,"excerpt":"About one year ago, I wrote about a simple example of Image Processing with LibJacket + OpenCV... and the trend continues today. In this post, I demonstrate how ArrayFire (an improved version of LibJacket) can easily interop with OpenCV, through a simple example of unsharp maksing (local contrast enhancement). \u00a0\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2012\/08\/Screen-Shot-2012-08-20-at-9.19.21-AM_2-1024x640.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2012\/08\/Screen-Shot-2012-08-20-at-9.19.21-AM_2-1024x640.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2012\/08\/Screen-Shot-2012-08-20-at-9.19.21-AM_2-1024x640.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1663,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/cuda-connected-component-labeling\/","url_meta":{"origin":1731,"position":4},"title":"GPU Connected Component Labeling","author":"mcclanahoochie","date":"August 6, 2011","format":false,"excerpt":"Connected Component Labeling (CCL): \"is used in computer vision to detect connected regions in binary digital images\", and sometimes referred to as blob coloring. Motivation: To keep AccelerEyes'\u00a0ever expanding GPU library growing, over a few weeks of this summer\u00a0I took on the project of writing a CUDA version of connected\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/coins-bwlabel-300x122.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2503,"url":"https:\/\/mcclanahoochie.com\/blog\/2012\/11\/sc12-arrayfire-webcam-demo\/","url_meta":{"origin":1731,"position":5},"title":"SC12 ArrayFire Demos","author":"mcclanahoochie","date":"November 25, 2012","format":false,"excerpt":"I got the\u00a0privilege\u00a0of developing some of the\u00a0Super Computing 2012\u00a0(SC12)\u00a0booth demos\u00a0for\u00a0AccelerEyes,\u00a0to showcase\u00a0ArrayFire. Above is an\u00a0ArrayFire\u00a0demo running at SC12 on an nVidia GPU. This demo (source code HERE) uses OpenCV to capture webcam video and processes the stream in several different ways, in real-time.\u00a0From top-left to bottom-right: Sobel filter, ArrayFire logo, Motion\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"Sobel filter, ArrayFire logo, Motion (frame differencing), Source image, Histogram plot, Mean-shift filter","src":"https:\/\/i0.wp.com\/lh5.googleusercontent.com\/-5haNiIGwpIk\/UKw-ct6OHDI\/AAAAAAAAMd8\/lxnzbUk44Kc\/s912\/20121114_111339.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts\/1731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/comments?post=1731"}],"version-history":[{"count":0,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts\/1731\/revisions"}],"wp:attachment":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/media?parent=1731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/categories?post=1731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/tags?post=1731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}