Похожие чаты

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

7 просмотров

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.

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

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

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта