opencl implementation of canny edge algorithm on java.awt.image.BufferedImage

asked 2018-01-31 10:54:55 -0500

updated 2018-01-31 21:37:26 -0500

I need some help understanding the opencl implementation for the canny edge detection algorithm.

I'm trying to compile and run this with jocl, with a java.awt.image.BufferedImage and I've succeeded in getting the kernals compiling. However, when I pass in the array into the kernal, I get no output and the output of the first stage looks like this:

Please let me know what I'm doing wrong and what else I may be able to do.

C:\fakepath\Screen Shot 2018-01-31 at 6.06.18 pm.png

The source code looks something like this. I followed the compilation process for canny.cpp and

(def canny-stage1 (kernel/load-executive
                   {:name "stage1_with_sobel"
                    :file "opencl/"
                    :options "-D WITH_SOBEL -D cn=1 -D TYPE=uchar -D convert_floatN=convert_float -D floatN=float -D GRP_SIZEX=32 -D GRP_SIZEY=8 -D L2GRAD"
                    :worksize (fn [src _ _ _ _ map _ _ _ _]
                                [(.getWidth  src)
                                 (.getHeight src)])
                    :arglist [{:type :image
                               :name :src
                               :buffer {:input true}
                               :flags [:read-only]}
                              {:type :int
                               :name :src-step}
                              {:type :int
                               :name :src-offset}
                              {:type :int
                               :name :rows}
                              {:type :int
                               :name :cols}
                              {:type :image
                               :name :map
                               :buffer {:output true}
                               :flags [:write-only]}
                              {:type :int
                               :name :map-step}
                              {:type :int
                               :name :map-offset}
                              {:type :float
                               :name :low-threshold}
                              {:type :float
                               :name :high-threshold}]}))

(def input (javax.imageio.ImageIO/read (io/file "lena-1000x1000.jpg"))

(def buffer (BufferedImage. (.getWidth input)
                               (.getHeight input)

(let [offset 0
        step (.getWidth input)
        rows (.getHeight input)
        cols (.getWidth input)]
    (canny-stage1 input

(display-image buffer)
edit retag flag offensive close merge delete


  • I'm trying to compile and run this with jocl -- so ? how is this related to opencv ?
  • no code shown, how do we know, what you're doing ?
berak gravatar imageberak ( 2018-01-31 11:11:16 -0500 )edit

The is in opencv for a Mat datastructure. I'm looking to compile the code in jocl and use it for java.awt.image.BufferedImage.

zcaudate gravatar imagezcaudate ( 2018-01-31 11:32:10 -0500 )edit

above is not even java (but what ?) -- again, i'm afraid, we cannot help you with any of your problems, specific to using some 3rd party wrappers)

berak gravatar imageberak ( 2018-01-31 11:35:51 -0500 )edit

it's clojure - which is java. I'm not wrapping anything. It's compiling the code and using it on a java.awt.image.BufferedImage object. The byte array is accessible via input.getRaster().getDataBuffer().getData(). I've found this to work with a custom method that also works with Mat but the code does not and I'm wondering why the stripes are occuring

zcaudate gravatar imagezcaudate ( 2018-01-31 11:44:24 -0500 )edit