I am collecting data (x,y) positions from an external computer vision program, and I am looking for an easy way to bring this data to panda. My aim for now is to use this data to move the mouse cursor.
I am exporting the data into a text file, and I would like to know, how can I open the file in panda, read the data and assign to the mouse cursor?
Unfortunately there is no example like this in the forums ( I wasnt expecting one!) so can somebody a bit more knowledgeable advice please?
If you actually want to move the mouse pointer, the little onscreen pointer that normally the user controls directly, you can do this with base.win.movePointer(x, y), where x and y are in the range -1 to 1 (not pixel values). There are plenty of examples for this in the forums; try searching for movePointer.
But I’d recommend against this. Better to control something onscreen that represents a mouse pointer, like a crosshairs or something that you attach to render2d. To do this, just do model.setPos(x, 0, y), where x and y are in the range 0 to 1. This is better because the mouse belongs to the user, and it’s rude to take control away from the user. In fact, Apple doesn’t even allow it because they consider it a poor user interface.
Thanks for your reply. I am actually using the base.mouseWatcherNode.getMouse, like the looking and gripping example. I will take your advice into consideration and try to use render2d. My question though concerned the next part.
Let me try to rephrase the problem. I have a text file with values taken from a computer vision system (this text file is being constantly updated with values) and I want to use this values to move the pointer.
How can I:
- open the text file in panda
- read the values
- assign this values to the mouse pointer? (either using render2d or base.win.movePointer(x,y)
I hope I am clear on what I mean. Thanks!
Sounds like you just want to use standard Python I/O calls, e.g.
file = open('data.txt', 'r')
for line in file.readlines():
words = line.split()
x = int(words)
y = int(words)
or whatever is appropriate for the format in which your file is written. I suggest a Python tutorial, or the information on python.org, for more information about these calls.
That is exactly what I want. I will follow your suggestion.
Just out of curiosity anyone here ever did a project using panda and a computer vision system?