Popular recipes tagged "mouse"http://code.activestate.com/recipes/tags/mouse/2012-06-26T18:08:25-07:00ActiveState Code RecipesClick counter for Windows (Python)
2012-06-26T18:08:25-07:00Krystian Rosińskihttp://code.activestate.com/recipes/users/4182314/http://code.activestate.com/recipes/578176-click-counter-for-windows/
<p style="color: grey">
Python
recipe 578176
by <a href="/recipes/users/4182314/">Krystian Rosiński</a>
(<a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Run script from cmd.</p>
OpenKinect Mouse Control Using Python (Python)
2012-04-15T18:49:00-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578104-openkinect-mouse-control-using-python/
<p style="color: grey">
Python
recipe 578104
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/computer_vision/">computer_vision</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/hand_tracking/">hand_tracking</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/opencv/">opencv</a>, <a href="/recipes/tags/openkinect/">openkinect</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tracking/">tracking</a>, <a href="/recipes/tags/vision/">vision</a>).
Revision 2.
</p>
<p>This is a simple code that lets a user control the mouse and left-click using the Microsoft Kinect, Python, and OpenKinect. </p>
<pre class="prettyprint"><code>Computer Prerequisites:
-OpenKinect
-Python Wrapper for OpenKinect
-A Linux machine using Ubuntu
-OpenCV 2.1
-OpenCV 2.3
-Python 2.7.2
-A Microsoft Kinect
-A Microsoft Kinect USB Adapter
-PyGame
-Xlib for Python
</code></pre>
<p>To run this code you either need to start it in the terminal or you need to write a short bash script that runs the code. This is necessary because it requires super-user privileges.</p>
<p>The Bash script is (Assuming the code is saved by the name 'Hand Tracking.py' in /home/$USER directory:</p>
<pre class="prettyprint"><code>#!bin/bash
cd 'home/$USER'
gksudo python 'Hand Tracking.py'
</code></pre>
<p>The code is heavily commented and most of what you will need to know is there. </p>
Control your mouse with the Microsoft Kinect using OpenKinect (Python)
2012-03-19T21:28:08-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578082-control-your-mouse-with-the-microsoft-kinect-using/
<p style="color: grey">
Python
recipe 578082
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/control/">control</a>, <a href="/recipes/tags/freenect/">freenect</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/microsoft/">microsoft</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/openkinect/">openkinect</a>, <a href="/recipes/tags/vision/">vision</a>, <a href="/recipes/tags/xlib/">xlib</a>).
</p>
<p>This is a simple code that uses the Kinect in order to simulate the mouse on the screen. In order for this code to work you must have a Linux machine, the freenect module from OpenKinect, NumPy, and Xlib. The last three can be downloaded and installed by running sudo apt-get install {PROGRAM NAME HERE}. Freenect needs to be downloaded and installed for python using the terminal and there are good instructions here how to do it <a href="http://openkinect.org/wiki/Getting_Started" rel="nofollow">http://openkinect.org/wiki/Getting_Started</a>. You will also need to install the python wrapper. This can be done by following the instructions on this site: <a href="http://openkinect.org/wiki/Python_Wrapper" rel="nofollow">http://openkinect.org/wiki/Python_Wrapper</a>. To run the code you must first cd into the directory in which the code resides and then in the terminal run the command sudo python {THE NAME YOU STORED THE CODE BELOW AS}.py. This should run the code. The code needs superuser privileges. Also if you wonder why the mouse will stop tracking your hand, there are two reasons. 1) This code is not super sophisticated, all it does is find the minimum point in the depth image and scales the coordinates to the size of the screen and moves the mouse there so if your stomach is the closest thing to the screen it will track it and place the mouse there. The other reason the mouse might stop tracking is because there is a counter in the that will only let it run 10000 iterations. This is just a safety precaution in case you are not able to control the mouse and the computer freaks out. The last thing you need to know to run this code is that the main_mouse() function takes to arguments, the first is the x dimension of your screen and the second is the y dimension. THE CODE WILL NOT FUNCTION PROPERLY ON MULTIDISPLAY COMPUTERS. Thank You</p>
mouse click to crop many large photos quickly [Python, PIL, pygame] (Python)
2012-01-09T03:18:01-08:00Elliot Hallmarkhttp://code.activestate.com/recipes/users/4180468/http://code.activestate.com/recipes/578005-mouse-click-to-crop-many-large-photos-quickly-pyth/
<p style="color: grey">
Python
recipe 578005
by <a href="/recipes/users/4180468/">Elliot Hallmark</a>
(<a href="/recipes/tags/crop/">crop</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/png/">png</a>).
</p>
<p>Waste no mouse clicks making multiple crops on many image files. Through pygame interface with pan, zoom and next/previous image. Saves files at new resolution and serialized names in a seperate folder. the mainloop() and helper functions are easy to reuse, but I include a cruddy text based interface if needed. if not, comment out most of __main__().</p>
<p>Requires PIL (python imaging library) and pygame.</p>