Похожие чаты

I have a couple of questions regarding this opencv python

code.

1.) The function gets called at CV.mousecallback() and the program enters the while loops until the program ends so the function should only be called once but instead it is called on every mouse click.. how does this work? Does calling setmousecallback make it run on a parallel thread and continuously check for mouse clicks or something?

2.) Inside the function, variables are declared as global so the changes made in the scope of the function are also applied to the global variables, however img is also changed when rectangle or circle functions are called and the change is reflected globally even though img is not defined to use the global variable.. how does this work?

2 ответов

10 просмотров

1.) I can't read that but if you bind a function to an event (like click) and want it to work only once and not every time you click, then at the end of the function unbind it. 2.) global variables are a headache, use classes that manage their own variables. It will be easier to figure out.

1. Yes, it runs on a different thread and creates new threads that executes the functions everytime a mouse click event happens. 2. img is used without initialization inside the function, the interpeter is smart enough to understand that you want the globaly defined img variable to be passed to the function call, the problem arises when you want to change the value of a parameter directly inside a function drawing = True; ix, iy = x, y the interpeter creates new variables in that case unless told otherwise.

Похожие вопросы

Обсуждают сегодня

Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
Ну вот просто даже давайте вот как. Какой нибудь конкретный кейс, можете в пример привести, где бч работает и приносит прикладную пользу, а не просто что бы было? Не крипту.
Alexander Andreev
22
For all those that keep asking why no pump? why this ? and why that...? Please close ur ewt chart and open 2 others - TOTAL (total mc) and BTC.D (btc dominance). Maybe BTC a...
Inn3r_G
19
"Since pnut can flip FTM easily, I'm swapping my FTM to pnut and hoping for a easy x5-x10" Perfect recipe for disaster. NFA but chances are, you'll end up as exit liquidity ...
C. A.
7
объясните пожалуйста, почему функция не работает должным образом? вроде должно брать активное окно сравнивать его размер с размером экрана, и если есть совпадение = true прове...
JF
9
AMD status update? No longer in the plan but something might be around the corner later on Chinese partner? No longer in the plan. This market does not seem to be the top ...
Ben
6
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
да кстати заметил всюда почему то всех сюда прёт, ни в одном чате столько ботов не прёт как сюда.. Может чота надо доработать?
REDis
15
Мне вот любопытно. Уже сколько времени имею соблазн купить макбук, ибо подозреваю что очень уж удобен будет в связке с другой техникой от эпл которая у меня есть, да и сам по ...
Not Yeromin
14
I get confused when people talk about the ‘bull market’ and the ‘next bull market’ as if anyone really has a clue what’s really going on in the world. First of all - there i...
Shah
1
Карта сайта