Gupta
How i acn upadate the value of the variable “square=0” as mention in my code so that after every loop it will update it by addind + 1 in “square=0”
this is my code :
def findcontours(path) do
#squares=0
{:ok, imgGrey} = OpenCV.imread(path, flags: OpenCV.cv_IMREAD_GRAYSCALE())
{:ok, {_, thrash}} = OpenCV.threshold(imgGrey, 240, 255, OpenCV.cv_THRESH_BINARY())
{:ok, {contours, _}} =OpenCV.findContours(thrash, OpenCV.cv_RETR_TREE(), OpenCV.cv_CHAIN_APPROX_NONE())
square = 0
for contour <- contours do
{:ok,peri} = OpenCV.arcLength(contour,true)
{:ok,approx} = OpenCV.approxPolyDP(contour, 0.01 * peri,true)
ap=OpenCV.Nx.to_nx(approx)
{len,_,_}=Nx.shape(ap)
if len==4 do #to bound squares from the countor
{:ok,{x1, y1, w, h}}= OpenCV.boundingRect(approx)
aspectRatio = (w/1)/h
if aspectRatio >= 0.95 and aspectRatio <= 1.05 and (y1+h)*(x1+w) < 985000 do
square=square +1
end
end
end
end
pls help me to update my value of square as i know there i a big problem of scope in elixir and also it is immutable so pls help me for this.
or suggest me another way so that i can do the whole process by another way if possible.
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Aetherus
In Elixir, variables are actually constants. You can’t reassign values to an existing variable. You can only create a new variable with the same name and shadow the old one.
This line
square = square + 1reads the value ofsquareoutside the for-loop, adds 1 to it, and creates a new variable also namedsquare, which is not used at all, because this newsquarevariable is inside a sub-sub scope of the for-loop, and the oldsquareis outside the for-loop. They are in different scopes.How to fix this?
Gupta
can u explain me briefly what u have done in this
so that in further code if i will face problem regarding this i can rectify it
Aetherus
Here’s a simple example of the
forcomprehension with the option:reduce:It’s equivalent to this code (I’m using the same variable names as in the snippet above):
The
forcomprehension first passes0, the value of the option:reduce, toacc, the first element in1..10ton, and apply the anonymous function toaccandn. Then it passes the return value of the anonymous function toacc, the second element in1..10ton, and apply the anonymous function again. So on and so forth, until there’s no element to take from1..10, then it returns the return value of the last call of that anonymous function.Aetherus
And note that both
for ... do ... endandif ... else ... endare expressions, and they have return values.The
ifwithoutelsereturns whatever inside theifblock returns, if the condition is met, otherwise, it returnsnil, which usually is not what you want, so be careful.Gupta
I was trying to use tesseract-Ocr in elixir
but i am getting error pls :
pls help me to rectify it
dimitarvp
It means the file path you specified does not exist.
Use
File.exists?insideiexto find the right file path.Gupta
I am getting error again :
why it is showing again this .
also i think i have the tesseract dependencies in mix.exs
but still it is showing me the error
dimitarvp
It’s expecting you to have
tesseractinstalled and put in the system PATH.What does
which tesseractshow you when you run it in a terminal?Gupta
This the path i have added in my system.
and this is my file location and location of my image grid_1.png is also there:
and this is my code with error i have written :
Now I am not getting where is the error , i am not able to read a single image.
dimitarvp
Have you run
which tesseract? If so, can you paste the output of the command?