From e8690821a8956f0684f11d885477ec75bde016a7 Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Sat, 4 Mar 2017 04:30:56 +0530 Subject: [PATCH 1/9] using c++ templates --- src/OpenCV_Mat.jl | 262 ++++++++++------------------------------------ 1 file changed, 56 insertions(+), 206 deletions(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index c488623..818f78a 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -1,214 +1,67 @@ # Get and set functions for access of pixel values in Mat image arrays -cxx""" -int at_u(cv::Mat &img, int row, int col) -{ - return(static_cast(img.at(row,col))); -} - -void at_u(cv::Mat &img, int row, int col, double val) -{ - uchar value = static_cast(val); - img.at(row,col) = value; -} - -int at_s(cv::Mat &img, int row, int col) -{ - return(static_cast(img.at(row,col))); -} - -void at_s(cv::Mat &img, int row, int col, double val) -{ - short value = static_cast(val); - img.at(row,col) = value; -} - -int at_us(cv::Mat &img, int row, int col) -{ - return(static_cast(img.at(row,col))); -} - -void at_us(cv::Mat &img, int row, int col, double val) -{ - unsigned short value = static_cast(val); - img.at(row,col) = value; -} -float at_f(cv::Mat &img, int row, int col) -{ - return(static_cast(img.at(row,col))); -} - -void at_f(cv::Mat &img, int row, int col, double val) -{ - float value = static_cast(val); - img.at(row,col) = value; -} - -double at_d(cv::Mat &img, int row, int col) -{ - return(static_cast(img.at(row,col))); -} - -void at_d(cv::Mat &img, int row, int col, double val) -{ - img.at(row,col) = val; -} - -std::vector at_vc(cv::Mat &img, int row, int col) -{ - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at>(row,col)[i]; }; return vec; -} - -void at_vc(cv::Mat& img, int row, int col, std::vector vec) -{ - for (int i = 0; i < 3; i++) { img.at>(row,col)[i] = static_cast(vec[i]); }; -} - -std::vector at_v3b(cv::Mat &img, int row, int col) -{ - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at(row,col)[i]; }; return vec; -} - -void at_v3b(cv::Mat &img, int row, int col, std::vector vec) -{ - for (int i = 0; i < 3; i++) {img.at(row,col)[i] = static_cast(vec[i]); }; -} - -std::vector at_v3s(cv::Mat &img, int row, int col) -{ - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at(row,col)[i]; }; return vec; -} - -void at_v3s(cv::Mat &img, int row, int col, std::vector vec) -{ - for (int i = 0; i < 3; i++) { img.at(row,col)[i] = static_cast(vec[i]); }; -} - -std::vector at_v3us(cv::Mat &img, int row, int col) -{ - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at>(row,col)[i]; }; return vec; -} - -void at_v3us(cv::Mat &img, int row, int col, std::vector vec) -{ - for (int i = 0; i < 3; i++) { img.at>(row,col)[i] = static_cast(vec[i]); }; -} - -std::vector at_v3i(cv::Mat &img, int row, int col) -{ - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at>(row,col)[i]; }; return vec; -} - -void at_v3i(cv::Mat &img, int row, int col,std::vector vec) +cxx""" +// Grayscale and binary images +template +inline T1 ptr_val(cv::Mat &img, int row, int col) { - for (int i = 0; i < 3; i++) { img.at>(row,col)[i] = static_cast(vec[i]); }; + return(static_cast(img.at(row, col))); } -std::vector at_v3f(cv::Mat &img, int row, int col) +template +inline void ptr_val(cv::Mat &img, int row, int col, double val) { - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at(row,col)[i]; }; return vec; + T2 value = static_cast(val); + img.at(row, col) = value; } -void at_v3f(cv::Mat &img, int row, int col, std::vector vec) +// RGB images +template +inline std::vector ptr_val3(cv::Mat &img, int row, int col) { - for (int i = 0; i < 3; i++) { img.at(row,col)[i] = static_cast(vec[i]); }; + std::vectorvec(3); + for(int i = 0; i < 3; ++i) + { + vec[i] = img.at>(row, col)[i]; + } + return vec; } -std::vector at_v3d(cv::Mat &img, int row, int col) +template +inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) { - std::vectorvec(3); - for (int i = 0; i < 3; i++) { vec[i]= img.at(row,col)[i]; }; return vec; + for(int i = 0; i < 3; ++i) + { + img.at>(row, col)[i] = static_cast(vec[i]); + } } -void at_v3d(cv::Mat &img, int row, int col, std::vector vec) -{ - for (int i = 0; i < 3; i++) { img.at(row,col)[i] = vec[i]; }; -} """ function pixget(img, row::Int, col::Int) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - # Grayscale and binary images (returns int) - if (cvtypeval(img) == CV_8UC1) - val = @cxx at_u(img, row, col); - #println(int(val)); return (val) - elseif (cvtypeval(img) == CV_16SC1) - val = @cxx at_s(img, row, col); - println(int(val)); return (val) - elseif (cvtypeval(img) == CV_32SC1) - val = @cxx at_us(img, row, col); - println(int(val)); return (val) - elseif (cvtypeval(img) == CV_32FC1) - val = @cxx at_f(img, row, col); - println(val); return (val) - elseif (cvtypeval(img) == CV_64FC1) - val = @cxx at_d(img, row, col); - println(val); return (val) - # RGB images (returns vec with original types) - elseif (cvtypeval(img) == CV_8SC3) - vec = @cxx at_vc(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)),int(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_8UC3) - vec = @cxx at_v3b(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)),int(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_16SC3) - vec = @cxx at_v3s(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)),int(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_16UC3) - vec = @cxx at_v3us(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)),int(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_32SC3) - vec = @cxx at_v3i(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)),int(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_32FC3) - vec = @cxx at_v3f(img, row, col); - println([float(at(vec, 0)), float(at(vec, 1)),float(at(vec, 2))]); return (vec) - elseif (cvtypeval(img) == CV_64FC3) - vec = @cxx at_v3d(img, row, col); - println([at(vec, 0), at(vec, 1),at(vec, 2)]); return (vec) - else throw(ArgumentError("Image format not recognized!")) - end + # Grayscale and binary images + val = @cxx ptr_val(img, row, col); + println(val) + return (val) + + # RGB images + vec = @cxx ptr_val3(img, row, col); + println([int(at(vec, 0)), int(at(vec, 1)), int(at(vec, 2))]) + return (vec) end function pixset(img, row::Int, col::Int, value) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - # Grayscale and binary images (value:: double) - if (cvtypeval(img) == CV_8UC1) - @cxx at_u(img, row, col, value); - elseif (cvtypeval(img) == CV_16SC1) - @cxx at_s(img, row, col, value); - elseif (cvtypeval(img) == CV_32SC1) - @cxx at_us(img, row, col, value); - elseif (cvtypeval(img) == CV_32FC1) - @cxx at_f(img, row, col, value); - elseif (cvtypeval(img) == CV_64FC1) - @cxx at_d(img, row, col, value); - # RGB images (value:: std::vector) - elseif (cvtypeval(img) == CV_8SC3) - @cxx at_vc(img, row, col, value); - elseif (cvtypeval(img) == CV_8UC3) - @cxx at_v3b(img, row, col, value); - elseif (cvtypeval(img) == CV_16SC3) - @cxx at_v3s(img, row, col, value); - elseif (cvtypeval(img) == CV_16UC3) - @cxx at_v3us(img, row, col, value); - elseif (cvtypeval(img) == CV_32SC3) - @cxx at_v3i(img, row, col, value); - elseif (cvtypeval(img) == CV_32FC3) - @cxx at_v3f(img, row, col, value); - elseif (cvtypeval(img) == CV_64FC3) - @cxx at_v3d(img, row, col, value); - else throw(ArgumentError("Image format not recognized!")) - end + + # Grayscale and binary images + @cxx ptr_val(img, row, col, value); + + # RGB images + @cxx ptr_val3(img, row, col, value); end # Using pointers to efficiently scan and manipulate whole Mat images: set functions @@ -216,10 +69,9 @@ cxx""" // grayscale/binary image void setgray(cv::Mat img, int val) { - for(int row = 0; row < img.rows; ++row) { + for(int row=0; row < img.rows; ++row) { uchar* p = img.ptr(row); - for(int col = 0; col < img.cols; ++col) { - //points to each pixel value in turn assuming a CV_8UC1 greyscale image + for(int col=0; col < img.cols; ++col){ *p++ = val; } } @@ -228,28 +80,26 @@ void setgray(cv::Mat img, int val) // color image void setcolor(cv::Mat img, std::vector color) { - int rows= img.rows; - int cols= img.cols; - - for (int row=0; row* p = img.ptr>(row,col); - p->x = color[0]; //B - p->y = color[1]; //G - p->z = color[2]; //R - } - } + int rows = img.rows; + int cols = img.cols; + + for(int row=0; row < rows; ++row){ + for(int col=0; col < cols; ++col){ + cv::Point3_* p = img.ptr>(row, col); + p->x = color[0]; //B + p->y = color[1]; //G + p->z = color[2]; //R + } + } } """ -# for grayscale/binary +# for grayscale / binary function setgray(img, val) @cxx setgray(img, val) end -# color/RGB +# color / RGB function setcolor(img, color) - @cxx setcolor(img, color) -end + @cxx setcolor(img, color) +end \ No newline at end of file From 3501983ccb6343ecb3f727deabb26b32a847f5a3 Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Sun, 5 Mar 2017 01:37:24 +0530 Subject: [PATCH 2/9] Adding tests for convertToMat method --- src/OpenCV_Mat.jl | 2 +- test/jl/tests.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index 818f78a..828ff08 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -102,4 +102,4 @@ end # color / RGB function setcolor(img, color) @cxx setcolor(img, color) -end \ No newline at end of file +end diff --git a/test/jl/tests.jl b/test/jl/tests.jl index e2e74a5..0fa2fe1 100644 --- a/test/jl/tests.jl +++ b/test/jl/tests.jl @@ -132,4 +132,18 @@ end test5() +################################################################################################ +# +# test 6: Conversion of images from Images.jl to OpenCV Mat +# +################################################################################################ + +function test6() + println("test 6: Conversion of images from Images.jl to OpenCV Mat") + filename = joinpath(Pkg.dir("OpenCV"), "./test/images/mandrill.jpg") + image = imread(filename) + dst = Mat(int(rows(image)), int(cols(image)), CV_8UC1) + dst = convertToMat(image) +end +test6() \ No newline at end of file From 3f9407499fbfc1718ace9abe2376591ba0203c4a Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Sun, 5 Mar 2017 19:06:05 +0530 Subject: [PATCH 3/9] fix bug --- src/OpenCV_Mat.jl | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index 828ff08..e03b6d3 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -41,27 +41,35 @@ inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) function pixget(img, row::Int, col::Int) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - - # Grayscale and binary images - val = @cxx ptr_val(img, row, col); - println(val) - return (val) - - # RGB images - vec = @cxx ptr_val3(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)), int(at(vec, 2))]) - return (vec) + image = Images.separate(img); + cd = Images.colordim(image); + + if cd < 3 + # Grayscale and binary images + val = @cxx ptr_val(img, row, col); + println(val) + return (val) + else + # RGB images + vec = @cxx ptr_val3(img, row, col); + println([int(at(vec, 0)), int(at(vec, 1)), int(at(vec, 2))]) + return (vec) + end end function pixset(img, row::Int, col::Int, value) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - - # Grayscale and binary images - @cxx ptr_val(img, row, col, value); - - # RGB images - @cxx ptr_val3(img, row, col, value); + image = Images.separate(img); + cd = Images.colordim(image); + + if cd < 3 + # Grayscale and binary images + @cxx ptr_val(img, row, col, value); + else + # RGB images + @cxx ptr_val3(img, row, col, value); + end end # Using pointers to efficiently scan and manipulate whole Mat images: set functions From 45927e6dbbffce82a1089ed3fe4328e95b6c446e Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Tue, 7 Mar 2017 12:38:43 +0530 Subject: [PATCH 4/9] use native functions --- src/OpenCV_Mat.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index e03b6d3..60c2bcb 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -41,8 +41,7 @@ inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) function pixget(img, row::Int, col::Int) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - image = Images.separate(img); - cd = Images.colordim(image); + cd = channels(img) if cd < 3 # Grayscale and binary images @@ -60,8 +59,7 @@ end function pixset(img, row::Int, col::Int, value) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - image = Images.separate(img); - cd = Images.colordim(image); + cd = channels(img) if cd < 3 # Grayscale and binary images From 7d4b6aa5fabb1322e08cd33196d2db9f075b80b7 Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Wed, 8 Mar 2017 03:16:16 +0530 Subject: [PATCH 5/9] deprecated int issue in 0.6.0 --- test/jl/tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jl/tests.jl b/test/jl/tests.jl index 0fa2fe1..2f32baa 100644 --- a/test/jl/tests.jl +++ b/test/jl/tests.jl @@ -142,7 +142,7 @@ function test6() println("test 6: Conversion of images from Images.jl to OpenCV Mat") filename = joinpath(Pkg.dir("OpenCV"), "./test/images/mandrill.jpg") image = imread(filename) - dst = Mat(int(rows(image)), int(cols(image)), CV_8UC1) + dst = Mat(Int(round(rows(image))), Int(round(cols(image))), CV_8UC1) dst = convertToMat(image) end From 3458803bdcc2dd92c4fa327a22bbb63e39d7b4ae Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Thu, 9 Mar 2017 02:48:23 +0530 Subject: [PATCH 6/9] update templates --- src/OpenCV_Mat.jl | 8 ++++---- test/jl/tests.jl | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index 91a386e..6a19061 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -4,13 +4,13 @@ cxx""" // Grayscale and binary images template -inline T1 ptr_val(cv::Mat &img, int row, int col) +inline T1 ptr_val(cv::Mat &img, int row, int col) { return(static_cast(img.at(row, col))); } template -inline void ptr_val(cv::Mat &img, int row, int col, double val) +inline void ptr_val(cv::Mat &img, int row, int col, double val) { T2 value = static_cast(val); img.at(row, col) = value; @@ -18,7 +18,7 @@ inline void ptr_val(cv::Mat &img, int row, int col, double val) // RGB images template -inline std::vector ptr_val3(cv::Mat &img, int row, int col) +inline std::vector ptr_val3(cv::Mat &img, int row, int col) { std::vectorvec(3); for(int i = 0; i < 3; ++i) @@ -29,7 +29,7 @@ inline std::vector ptr_val3(cv::Mat &img, int row, int col) } template -inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) +inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) { for(int i = 0; i < 3; ++i) { diff --git a/test/jl/tests.jl b/test/jl/tests.jl index 2f32baa..56a396a 100644 --- a/test/jl/tests.jl +++ b/test/jl/tests.jl @@ -58,7 +58,7 @@ function test3() println("test 3: Binary thresholding") filename = joinpath(Pkg.dir("OpenCV"), "./test/images/lena.png") img = imread(filename) - dst = Mat(int(rows(img)), int(cols(img)), CV_8UC1) + dst = Mat(Int(round(rows(img))), Int(round(cols(img))), CV_8UC1) cvtColor(img, dst, COLOR_BGR2GRAY) gaussianBlur(dst, dst, cvSize(5,5)) thresh = Mat() From d94f8ad9d484d72dbc2b16e627d71eddd9a5ff10 Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Thu, 9 Mar 2017 03:49:31 +0530 Subject: [PATCH 7/9] Adding Images dependency for tests --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 7139f8e..01eb6d0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using OpenCV using Base.Test +using Images include(joinpath(Pkg.dir("OpenCV"), "./test/jl/tests.jl")) From c4729c61a4e3cac0988ee6d8632c1cfca11a1587 Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Fri, 10 Mar 2017 13:03:32 +0530 Subject: [PATCH 8/9] new approach to templates --- src/OpenCV_Mat.jl | 102 +++++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/src/OpenCV_Mat.jl b/src/OpenCV_Mat.jl index 6a19061..b3a46cb 100644 --- a/src/OpenCV_Mat.jl +++ b/src/OpenCV_Mat.jl @@ -3,37 +3,37 @@ cxx""" // Grayscale and binary images -template -inline T1 ptr_val(cv::Mat &img, int row, int col) +template +inline T ptr_val(cv::Mat &img, int row, int col) { - return(static_cast(img.at(row, col))); + return(static_cast(img.at(row, col))); } -template -inline void ptr_val(cv::Mat &img, int row, int col, double val) +template +inline void ptr_val(cv::Mat &img, int row, int col, double val) { - T2 value = static_cast(val); - img.at(row, col) = value; + T value = static_cast(val); + img.at(row, col) = value; } // RGB images -template -inline std::vector ptr_val3(cv::Mat &img, int row, int col) +template +inline std::vector ptr_val3(cv::Mat &img, int row, int col) { - std::vectorvec(3); + std::vectorvec(3); for(int i = 0; i < 3; ++i) { - vec[i] = img.at>(row, col)[i]; + vec[i] = img.at>(row, col)[i]; } return vec; } -template -inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) +template +inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec) { for(int i = 0; i < 3; ++i) { - img.at>(row, col)[i] = static_cast(vec[i]); + img.at>(row, col)[i] = static_cast(vec[i]); } } @@ -41,32 +41,68 @@ inline void ptr_val3(cv::Mat &img, int row, int col, std::vector vec function pixget(img, row::Int, col::Int) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothingcpp_templates - cd = channels(img) - if cd < 3 - # Grayscale and binary images - val = @cxx ptr_val(img, row, col); - println(val) - return (val) - else - # RGB images - vec = @cxx ptr_val3(img, row, col); - println([int(at(vec, 0)), int(at(vec, 1)), int(at(vec, 2))]) - return (vec) + # Grayscale and binary images + if (cvtypeval(img) == CV_8UC1) + val = @cxx ptr_val(img, row, col); + elseif (cvtypeval(img) == CV_16SC1) + val = @cxx ptr_val(img, row, col); + elseif (cvtypeval(img) == CV_32SC1) + val = @cxx ptr_val(img, row, col); + elseif (cvtypeval(img) == CV_32FC1) + val = @cxx ptr_val(img, row, col); + elseif (cvtypeval(img) == CV_64FC1) + val = @cxx ptr_val(img, row, col); + # RGB images + elseif (cvtypeval(img) == CV_8SC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_8UC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_16SC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_16UC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_32SC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_32FC3) + vec = @cxx ptr_val3(img, row, col); + elseif (cvtypeval(img) == CV_64FC3) + vec = @cxx ptr_val3(img, row, col); + else throw(ArgumentError("Image format not recognized!")) end end function pixset(img, row::Int, col::Int, value) (row < 0 || col < 0 || row > rows(img) || col > cols(img)) ? throw(BoundsError()) : nothing - cd = channels(img) - - if cd < 3 - # Grayscale and binary images - @cxx ptr_val(img, row, col, value); - else - # RGB images - @cxx ptr_val3(img, row, col, value); + + # Grayscale and binary images + if (cvtypeval(img) == CV_8UC1) + @cxx ptr_val(img, row, col, value); + elseif (cvtypeval(img) == CV_16SC1) + @cxx ptr_val(img, row, col, value); + elseif (cvtypeval(img) == CV_32SC1) + @cxx ptr_val(img, row, col, value); + elseif (cvtypeval(img) == CV_32FC1) + @cxx ptr_val(img, row, col, value); + elseif (cvtypeval(img) == CV_64FC1) + @cxx ptr_val(img, row, col, value); + # RGB images + elseif (cvtypeval(img) == CV_8SC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_8UC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_16SC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_16UC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_32SC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_32FC3) + @cxx ptr_val3(img, row, col, value); + elseif (cvtypeval(img) == CV_64FC3) + @cxx ptr_val3(img, row, col, value); + else throw(ArgumentError("Image format not recognized!")) end end From 42447f7b293b472f3092cc049d476092c6c8b7bd Mon Sep 17 00:00:00 2001 From: kvmanohar22 Date: Fri, 10 Mar 2017 18:39:20 +0530 Subject: [PATCH 9/9] remove deprecated functionalities --- src/OpenCV_ImagesSupport.jl | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/OpenCV_ImagesSupport.jl b/src/OpenCV_ImagesSupport.jl index d3ff1e4..88a10e1 100644 --- a/src/OpenCV_ImagesSupport.jl +++ b/src/OpenCV_ImagesSupport.jl @@ -7,24 +7,27 @@ # Use * pointer indexing instead of the "at" method implemented in pixset function convertToMat(image) - img = Images.separate(image); - cd = Images.colordim(img); + img = permuteddimsview(channelview(image), (2,3,1)) + cd = Base.size(channelview(image))[1] > 3 ? 1 : 3 + _rows = Base.size(image, 1) + _cols = Base.size(image, 2) + if (typeof(img[1,1,1].i) == UInt8) - if (cd < 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_8UC1); end - if (cd == 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_8UC3); end + if (cd < 3); mat = Mat(_rows, _cols, CV_8UC1); end + if (cd == 3); mat = Mat(_rows, _cols, CV_8UC3); end elseif (typeof(img[1,1,1].i) == Float32) - if (cd < 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_32FC1); end - if (cd == 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_32FC3); end + if (cd < 3); mat = Mat(_rows, _cols, CV_32FC1); end + if (cd == 3); mat = Mat(_rows, _cols, CV_32FC3); end elseif (typeof(img[1,1,1].i) == Float64) - if (cd < 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_64FC1); end - if (cd == 3); mat = Mat(Base.size(img,2), Base.size(img,1), CV_64FC3); end + if (cd < 3); mat = Mat(_rows, _cols, CV_64FC1); end + if (cd == 3); mat = Mat(_rows, _cols, CV_64FC3); end else throw(ArgumentError("Pixel format not supported!")) end if (cd < 3) # grayscale or binary - for j = 1:Base.size(img,2) # index row first (Mat is row-major order) - for k =1:Base.size(img,1) # index column second + for j = 1:_rows # index row first (Mat is row-major order) + for k =1:_cols # index column second # slow algorithm - will try to use pointer method (C++)! pixset(mat, k, j, float(img[k,j,1].i)) end @@ -32,8 +35,8 @@ function convertToMat(image) end if (cd == 3) # color (RGB) image - for j = 1:Base.size(img,2) # index row first (Mat is row-major order) - for k =1:Base.size(img,1) # index column second + for j = 1:_rows # index row first (Mat is row-major order) + for k =1:_cols # index column second colorvec = tostdvec([float(img[k,j,1].i),float(img[k,j,2].i),float(img[k,j,3].i)]) pixset(mat, k-1, j-1, colorvec) # -1 to have 0-indexing per C++ end