Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type signature issue with "polylines" #18

Open
ghost opened this issue Dec 27, 2022 · 5 comments
Open

Type signature issue with "polylines" #18

ghost opened this issue Dec 27, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Dec 27, 2022

So far, everything seems to be working. I'm converting some OpenCV C++ demos to Julia OpenCV. I'm having problems with the "polylines", in particular the second argument isn't matching.

I'm passing "Vector{Array{Int32, 3}}" but it's not matching with the second argument. Here's the error:

ERROR: LoadError: MethodError: no method matching polylines(::OpenCV.Mat{UInt8}, ::Vector{Array{Int32, 3}}, ::Bool, ::Tuple{Int64, Int64, Int64}; thickness=5)
Closest candidates are:
polylines(::Union{OpenCV.CxxMat, AbstractArray{T, 3} where T<:Union{Float32, Float64, Int16, Int32, Int8, UInt16, UInt8}}, ::Vector{Union{OpenCV.CxxMat, AbstractArray{T, 3} where T<:Union{Float32, Float64, Int16, Int32, Int8, UInt16, UInt8}}}, ::Bool, ::Union{Tuple{}, Tuple{Number}, Tuple{Number, Number}, Tuple{Number, Number, Number}, NTuple{4, Number}}; thickness, lineType, shift) at ~/.julia/artifacts/365b03f782c1e4bef434b771da708a9d46aeb711/OpenCV/src/cv_cxx_wrap.jl:1902

I'm learning Julia and was on the discord server. The comments that I'm getting is that the signature isn't quite right. They're suggesting: "Vector{<:cv.InputArray}".

Here's the source code:

import OpenCV as cv

const NAME = "Open CV Window"

pt(x, y) = cv.Point{Int32}(x, y)
sz(x, y) = cv.Size{Int32}(x, y)
pp(x, y) = begin
	reshape([Int32(x), Int32(y)], (1, 1, 2))
end

function demo3()
	try
		img = cv.Mat(zeros(UInt8, (3, 640, 480)))
		cv.line(img, pt(0, 0), pt(100, 200), (255, 0, 0); thickness=5)
		cv.rectangle(img, pt(384, 0), pt(510, 128), (0, 0, 255); thickness=-1)
		cv.ellipse(img, pt(256, 256), sz(100, 50), 0.0, 0.0, 180.0, (0, 255, 0); thickness=-1)
		pts = [ pp(10, 5), pp(20, 30), pp(70, 20), pp(50, 10)] 
		println(typeof(pts))
		cv.polylines(img, pts, false, (0, 255, 255); thickness=5)
		cv.imshow(NAME, img)
		cv.waitKey(0)
	finally
		cv.destroyAllWindows()
	end
end

demo3()

Was playing around and saw the following

# this works
julia> Array{Int32, 3} <: cv.InputArray
true
# wrapping with "Vector" breaks
julia> Vector{Array{Int32, 3}} <: Vector{cv.InputArray}
false
@ashwani-rathee
Copy link
Member

Hey @MontyTHall2, could you share your demos?

@jochalek
Copy link

jochalek commented Jul 21, 2023

I'm running into a similar issue with OpenCV.fillPoly.

I cannot determine a data type that successfully dispatches as a Vector{InputArray}.

Given that InputArray is

julia> OpenCV.InputArray
Union{OpenCV.CxxMat, AbstractArray{T, 3} where T<:Union{Float32, Float64, Int16, Int32, Int8, UInt16, UInt8}}

I'm wondering if this is related to :

julia> Vector{Float64} <: Vector{Real}
false
julia> Vector{Float64} <: Vector{<:Real}
true

For example.

julia> Vector{Array{Int32, 3}} <: Vector{OpenCV.InputArray}
false
julia> Vector{Array{Int32, 3}} <: Vector{<:OpenCV.InputArray}
true

I'm not familiar with CxxWrap.jl and I think digging deeper into how the function arguments are defined is beyond my Julia knowledge at the moment.

@rakeshksr
Copy link
Member

I am also facing similar issue with OpenCV.drawContours

MethodError: no method matching drawContours(::Array{UInt8, 3}, ::Vector{OpenCV.Mat{Int32}}, ::Int64, ::Tuple{Int64}; thickness::Int64)

Closest candidates are:

drawContours(::Union{OpenCV.CxxMat, AbstractArray{T, 3} where T<:Union{Float32, Float64, Int16, Int32, Int8, UInt16, UInt8}}, !Matched::Vector{Union{OpenCV.CxxMat, AbstractArray{T, 3} where T<:Union{Float32, Float64, Int16, Int32, Int8, UInt16, UInt8}}}, ::Int64, ::Union{Tuple{}, Tuple{Number}, Tuple{Number, Number}, Tuple{Number, Number, Number}, NTuple{4, Number}}; thickness, lineType, hierarchy, maxLevel, offset)

@tobias-kehrer
Copy link

I am having the same issue with OpenCV.drawContours as @rakeshksr mentioned.

I fixed the MethodError by replacing

drawContours(image::InputArray, contours::Array{InputArray, 1}, ...

in cv_cxx_wrap.jl:2147 and cv_cxx_wrap.jl:2150 with

drawContours(image::InputArray, contours::Array{<:InputArray, 1}, ...

(Note the added <:)

However contours are not detected correctly.

@likanzhan
Copy link

Experienced similar issue when using the function OpenCV.boundingRect

@rakeshksr rakeshksr added the bug Something isn't working label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants