Why is calling OpenCV.pyrDown( ) from Julia work for halving the image size, but not for quartering it?

Viewed 68

I've recently created a build of OpenCV with Julia bindings. It's probably because I'm new to Julia, but it's been challenging getting the appropriate argument typing for the opencv function calls. Anyway, I managed to get the code below executing properly so that it renders a half-scale version of the images captured from a web cam with just a little latency and at 15 fps, but when I re-run it with a change to scale the image down to one-fourth of the size, it core dumps.

So this works:

print("Initializing OpenCV...")

using Printf
using OpenCV
cv = OpenCV

cap = cv.VideoCapture("/dev/video0")

global count = 0

print("Ready\n ",count)

scaleDown = 2

while (cv.isOpened(cap))
    global count
    ret,img = cv.read(cap)
    c,w,h=size(img)
    @printf("%d %d %d\n",c,w,h)
    sz = cv.Size(Int32(w÷scaleDown),Int32(h÷scaleDown))
    img2 = cv.pyrDown(img,dstsize=sz)
    count = count + 1
    cv.imshow("Down",img2)
    if cv.waitKey(Int32(1)) & 0xFF == Int('q')
        break
    end
end

cv.release(cap)
cv.destroyAllWindows()

print(count)

However, if scaleDown is set to 4, this results:

signal (6): Aborted
in expression starting at /home/kevin/Projects3/video-test.jl:15
gsignal at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f27ba2e3675)
_ZN2cv5errorEiRKNSt7__ ... _wrapEUlS2_S2_S5_S6_E387_E9_M_invokeERKSt9_Any_dataS2_S2_S5_S6_ at /home/kevin/Projects2/build/OpenCV/src/lib/libopencv_julia (unknown line)
_ZN5jlcxx6detail11CallFunctorIN2cv3MatEJRS3_S4_RNS2_5Size_IiEERiEE5applyEPKvNS_13WrappedCppPtrESC_SC_SC_ at /home/kevin/Projects2/build/OpenCV/src/lib/libopencv_julia (unknown line)
jlopencv_cv_cv_pyrDown at /home/kevin/.julia/packages/CxxWrap/ZOkSN/src/CxxWrap.jl:590
pyrDown at /home/kevin/Projects2/build/OpenCV/src/cv_cxx_wrap.jl:1162 [inlined]
#pyrDown#57 at /home/kevin/Projects2/build/OpenCV/src/cv_cxx_wrap.jl:1164 [inlined]
pyrDown##kw at /home/kevin/Projects2/build/OpenCV/src/cv_cxx_wrap.jl:1164
unknown function (ip: 0x7f279e09f055)
top-level scope at /home/kevin/Projects3/video-test.jl:21
unknown function (ip: 0x7f27be5ec030)
unknown function (ip: 0x7f27be5c7105)
jl_load at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
include at ./Base.jl:377
exec_options at ./client.jl:288
_start at ./client.jl:484
jfptr__start_2075.clone_1 at /usr/lib/x86_64-linux-gnu/julia/sys.so (unknown line)
unknown function (ip: 0x55ece9ac99d9)
unknown function (ip: 0x55ece9ac95a6)
__libc_start_main at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x55ece9ac964d)
Allocations: 10815726 (Pool: 10814596; Big: 1130); GC: 3
Aborted (core dumped)

Why?

1 Answers

Please refer to the documentation for pyrDown at https://docs.opencv.org/3.4/d4/d86/group__imgproc__filter.html#gaf9bba239dfca11654cb7f50f889fc2ff

In particular, I believe the dstsize is failing the condition and causing an assert to be raised. For some reason, your build is not handling it properly.

I tried the same thing with a debug build and I'm getting the proper error message as

ERROR: OpenCV(4.4.0-pre) /home/archit/GSoC_Work/opencv/modules/imgproc/src/pyramids.cpp:759: error: (-215:Assertion failed) ssize.width > 0 && ssize.height > 0 && std::abs(dsize.width*2 - ssize.width) <= 2 && std::abs(dsize.height*2 - ssize.height) <= 2 in function 'pyrDown_'

Stacktrace:
 [1] jlopencv_cv_cv_pyrDown(::OpenCV.CxxMatAllocated, ::OpenCV.CxxMatAllocated, ::OpenCV.Size{Int32}, ::Int32) at /home/archit/.julia/packages/CxxWrap/ZOkSN/src/CxxWrap.jl:590
 [2] pyrDown at /home/archit/GSoC_Work/opencv_build/OpenCV/src/cv_cxx_wrap.jl:1141 [inlined]
 [3] #pyrDown#57 at /home/archit/GSoC_Work/opencv_build/OpenCV/src/cv_cxx_wrap.jl:1143 [inlined]
 [4] top-level scope at ./REPL[9]:7

Can you share the exact version of Julia that you used along with the build commands so that I can identify why the error wasn't properly handled?

Related