You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to do hand gesture recogniton and convexity defects seemed a pretty resonable to do that with classic image processing but we didn't have a implementation for this(OpenCV does) so using what we have currently,I wrote this implementation:
using LazySets, StaticArrays
functionfindconvexitydefects(
contour,
convhull;
dist=1.1,
absdiff=10,
mindist=0,
currsize=50 )
# first we need to match our contours and our convehull regions
numindices = []
previous =0for i in convhull
for (num,j) inenumerate(contour)
ifnorm(Tuple(i) .-Tuple(j)) < dist &&abs(previous-num) > absdiff # to avoid small and very close regionspush!(numindices, num)
previous = num
breakendendend# we want the numindices same as our convhull points, # to define regions of interest for each convhull line
defects =Vector{CartesianIndex{2}}([]) # indexes with defects# incase numndices < convhull indexes, # meaning we don't hv regions for all linesifsize(numindices)[1] <size(convhull)[1]
throw(error("Raise the range dist, numindices points less than convexhull points, $(size(numindices)[1])"))
end# iterate over each consecutive pair of convhull points to form linefor i in1:size(convhull)[1]-1# to handle the case where numindices are like 1256, then 1if numindices[i] > numindices[i+1]
curr =vcat(contour[numindices[i]:end], contour[1: numindices[i+1]])
else# general case to define contours poins for each convhull region
curr = contour[numindices[i]:numindices[i+1]]
end# to remove minor regions of contours, we can set currsizeifsize(curr)[1] < currsize
continueend# Defining the line
p1 =Float64.(Tuple(convhull[i])) # point 1
p2 =Float64.(Tuple(convhull[i+1])) # point 2
line =Line(;from=[p1[1], p1[2]], to=[p2[1], p2[2]])
maxdef =0# max distance from our convhull line
defloc =CartesianIndex(0,0) # location of the that point# check for each contour point in a convhull region# their distance and find max distance pointfor j in curr
p = SA[j[1], j[2]]
lpdist =distance(p, line) # find distance# update if we find new maxif lpdist > maxdef
maxdef = lpdist
defloc = j
endend# we can define what minimum distance from line should beif maxdef > mindist
push!(defects, defloc)
endendreturn defects
end
Issue that can be solved is I think synchronise convehull and contours points to remove the first loop am not sure if we have a proper findcontours/bwboundaries in juliaimages but I used suzuki and abe algorithm exampe provided by archit rungta
We want to find the blue points which are away from convexhull. I thought given that convexhull(in ImageMorphology.jl) uses a binary mask, so it must be finding the boundaries/contours somehow, so maybe we can use that(avoid contour calc 1 time) but then it only uses partial part of the boundaries using the getboundarypoints() function(rightmost image)
Images:
MRE
using Images, ImageDraw
img =Gray.(load("img592.png"))
img =mapwindow(ImageFiltering.median, dilate(dilate(dilate(dilate(img)))), (15, 15))
contours =find_contours(img) # https://juliaimages.org/v0.22/democards/examples/contours/contour_detection/
convhull =convexhull(img .>0.5)
push!(convhull, convhull[1])
functiondrawdots!(img, res, color )
for i in res
img[i[1]-10:i[1]+10, i[2]-10:i[2]+10] .= color
endend
res =findconvexitydefects(contours[1], convhull; dist=3, absdiff =1, currsize=80, mindist =10)
img_convex1 =RGB{N0f8}.(ones(size(img)))
drawdots!(img_convex1, res, RGB(0,0,1))
draw!(img_convex1, ImageDraw.Path(convhull), RGB(0))
draw_contours(img_convex1, RGB(0), contours) # again availble in archit tut
[img img_convex1]
Would love to have this in here and have a discussion
The text was updated successfully, but these errors were encountered:
I was trying to do hand gesture recogniton and convexity defects seemed a pretty resonable to do that with classic image processing but we didn't have a implementation for this(OpenCV does) so using what we have currently,I wrote this implementation:
Issue that can be solved is I think synchronise convehull and contours points to remove the first loop am not sure if we have a proper findcontours/bwboundaries in juliaimages but I used suzuki and abe algorithm exampe provided by archit rungta
We want to find the blue points which are away from convexhull. I thought given that convexhull(in ImageMorphology.jl) uses a binary mask, so it must be finding the boundaries/contours somehow, so maybe we can use that(avoid contour calc 1 time) but then it only uses partial part of the boundaries using the getboundarypoints() function(rightmost image)
Images:
MRE
Would love to have this in here and have a discussion
The text was updated successfully, but these errors were encountered: