herisson

herisson

Evision.moments(contour) returns empty map

Hi!
I’m currently trying to implement a simple point detection pipeline in order to get the points positions in an image :

For that, I start by finding contours in the image, then try to use the cv.moments(contour) function to find their centroid.

img = Evision.imread("***/elixir/membrane/points-img.png")
bw = Evision.imread("***/elixir/membrane/points-img.png",  flags: Evision.Constant.cv_IMREAD_GRAYSCALE())
|> Evision.threshold(50, 255, Evision.Constant.cv_THRESH_BINARY())
|> then(fn {_, mat} -> mat end)


{contours, _ } = Evision.findContours(bw, Evision.Constant.cv_RETR_TREE(), Evision.Constant.cv_CHAIN_APPROX_SIMPLE())

contours
|> Enum.map(fn c -> 
  moments = Evision.moments(c, binaryImage: true)
  IO.inspect(Evision.contourArea(c), label: "Contour area")
  moments
  end)
|> IO.inspect()

However, the Evision.moments function always returns an empty map. (I tried contourArea just to debug)
output:

Contour area: 193.0
Contour area: 197.5
Contour area: 110.0
[%{}, %{}, %{}]

Am I doing something wrong, or is this an issue on the bindings side?
Thanks for the help !

EDIT:
changing binaryImage to false did not change anything

Most Liked

mortenlund

mortenlund

This is my experience as well.
If I cannot make it work I will make an issue for this in the Evision repo, he was very helpful to fix issues! :smiley:

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement