Похожие чаты

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 ответов

11 просмотров

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.

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта