×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Python + Motion detection = Fweemote

timothy posted more than 6 years ago | from the help-tom-cruise-find-future-crime dept.

Input Devices 30

jedie writes "After reading about different Wiimote hacks on Slashdot I decided to make a video with some demos of my motion-detection library. You can watch the video here. There's a link to the sourcecode (GPL) as well, but the demo is win32 only. It's basically a webcam and some software in python to track LEDs (preferrably IRs). In the demo video, you see the software (albeit badly because of the webcam's IR filter being removed) tracking two differently colored LEDs, so multiplayer is possible. The software can track multiple points easily, and when combined with IR-LEDs, it's easy to simulate one Wiimote (i.e. calculating the distance and angle between two IR-LEDs to determine where the remote is relative to the webcam). I want the code to get some publicity, because I don't have time to work on it (dissertation, blabla) but I don't want the code (however messy it is) to go to waste."

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

30 comments

Win32 because of webcam library (1)

doxology (636469) | more than 6 years ago | (#21816368)

This is not surprising, since I was unable to find any really good Linux python webcam libraries (and by really good, I mean, any that I could get to work).

Re:Win32 because of webcam library (-1, Offtopic)

Anonymous Coward | more than 6 years ago | (#21816524)

this one works quite well if you know what you are doing [dwarfurl.com]

Re:Win32 because of webcam library (0)

Anonymous Coward | more than 6 years ago | (#21816732)

Beware the URL masking on this link, it likely redirects to garbage or worse..

Re:Win32 because of webcam library (0)

Anonymous Coward | more than 6 years ago | (#21817052)

Another one of those stupid myminicity links. What the hell is up with that place?

Re:Win32 because of webcam library (0)

Anonymous Coward | more than 6 years ago | (#21817366)

Its a place for having fun, really I go there of my own free will.

Re:Win32 because of webcam library (1)

armareum (925270) | more than 6 years ago | (#21818150)

It encourages spam of forums. Likely for extra hits from unique IP addresses for ad purposes. The people who are spamming are effectively working for that website, even though they think they are playing a game. Kinda ingenious, but still annoying nevertheless.

Re:Win32 because of webcam library (4, Informative)

delire (809063) | more than 6 years ago | (#21816886)

What's wrong with the Python interface to Intel's immensely popular OpenCV [opencv.org]. Firewire devices, USB, multiple cameras.. all are a breeze on Linux or those-other-two-popular-OS's.

Using a Debian-based system as example:

apt-get install python-opencv

In a Python interpreter do:

from opencv import cv

then:

help(cv)

.. and prosper.

Re:Win32 because of webcam library (3, Funny)

doxology (636469) | more than 6 years ago | (#21817292)

Apparently, it's not very good at letting me know it exists =P. Thanks, I'll give it a whirl.

If only (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21816390)

You would have used a proper language...

Re:If only (0)

Anonymous Coward | more than 6 years ago | (#21816606)

What difference does the language make, you dumb kid? Gah, Slashdot sucks these days, with all these people who think they understand programming.

Re:If only (2, Informative)

Malevolyn (776946) | more than 6 years ago | (#21816698)

I hear that. Anyone with any real knowledge knows that these days language is mostly a matter of preference. Of course, Python is my language of choice and I do love how beautiful the code looks no matter how convoluted you try and write it.

raw = os.popen('dir /B').read().rstrip().split('\n')
To be perfectly honest, however, I use certain languages for different things. Rather, I use Perl for IM stuff (AIM, IRC, etc), PHP on my sites, and Python for those two plus everything else including a teaching tool.

Re:If only (1)

xenocide2 (231786) | more than 6 years ago | (#21817032)

So what exactly does that code do? Read an entire directory contents and store the results into an array? The code might look beautiful, but it's no wonder now why python's a memory hog if thats how people use it.

Re:If only (1)

abigor (540274) | more than 6 years ago | (#21817072)

Well, in all fairness, maybe he simply wanted to have the contents of the directory in an array, regardless of the language used? After all, all languages give you the ability to do things in a silly or inefficient manner. Some just look worse than others while doing it ;)

Re:If only (1, Insightful)

Anonymous Coward | more than 6 years ago | (#21817770)

I'm sick of people talking about how slow and memory-abusive Python can be. It has changed quite a bit since those negative reviews came out 8 years ago.

Compare it to PHP on the infamous Language Shootout site and you'll see Python is better in every way:
http://shootout.alioth.debian.org/debian/benchmark.php?test=all&lang=python&lang2=php [debian.org]

The same site shows that for both speed and memory use, Python is really better than most other languages. It even beats plain C++/gcc and C# on string manipulations/regex thanks to the optimized standard libraries that it ships with. Best of all, compare the code for these benchmarks and tell me which you would rather maintain. The DNA-regex test is >1500 bytes of gzipped C# and about 300 bytes of python (and yes, the python uses less memory).

In short: write less code with duck typing and intuitive OO & syntax and still run quickly and don't use much memory. Python wins for quickly writing general apps and tools (the "glue" in larger suites).

Re:If only (1)

xenocide2 (231786) | more than 6 years ago | (#21819380)

Comparing to PHP is like shooting fish in a barrel.

Try this one [debian.org] on for size.

All the crap Pythonites love to boast about and almost universally faster. I'd be careful using the Shootout as a reference though, as not every language gets the love it needs to get a fair shake in such comparisons. In the Python case, Regex DNA has seen some serious love that picked the best concepts from the other implementations in the pursuit of speed. Its place in the ranking is likely not a matter of libraries, as it uses the same libs as the other one.

Note that duck typing restricts the compiler from assuming a function can only take a specific type of object, requiring access to all members and methods of all objects to do a type check first. I like OCaml's typing system for being quite specific, and concise. A tree can be defined thusly in Ocaml:

type tree = Leaf | Node of tree * tree;

Of course, you're missing operations on it, and Objective Caml naturally provides OO ways of doing things. But I've never heavily researched the subject. As I once read and believe, most every pattern in the GoF is trivially obvious in a functional language. I'm also fairly sure they're much simpler to read and write in a functional language.

Re:If only (1)

pembo13 (770295) | more than 6 years ago | (#21818118)

You can do the same thing in Java and C# if you would like. Seriously. I wonder if you have any proof that Python is a memory hog.

Re:If only (0)

ILuvRamen (1026668) | more than 6 years ago | (#21817064)

I don't program in any version of C cuz I can never type those damn square brackets [] correctly the first time lol. I use VB cuz I love the dots! Dot madness!! Just kidding, I use it cuz I like subtracting two date and time values with one command in one line which is why I was gonna say you're partially wrong. It's personal preference but it's not like you can just pick any language and it'll be basically the same. If you choose VB instead of C-anything, you're gonna spend way less time writing the app and it's gonna be a pretty bloated, inefficient app. It's waaay more than preference, it's what the program is gonne be used for. Don't write your backbone apps in VB and don't write a one week little utility project in a C language no matter what language you prefer.
And I don't think your code sample looks pretty lol

Re:If only (3, Funny)

JohnFluxx (413620) | more than 6 years ago | (#21817344)

> I don't program in any version of C cuz I can never type those damn square brackets [] correctly

You can't write 'because' either.

Re:If only (1)

Malevolyn (776946) | more than 6 years ago | (#21817362)

It depends on what you're comfortable with. I know a more C than VB, more Perl than C, more Python than Perl. Certain languages may be easier (from whatever point of view) but that doesn't mean they're easier for everyone. Some people do write backbone apps in VB, and some write simple little squirts of software in C. I'm not saying it's a good idea (because I do agree with you) but for some it's just easier to stick with what you know.

Re:If only (1)

dolmen.fr (583400) | more than 6 years ago | (#21817144)

I do love how beautiful the code looks no matter how convoluted you try and write it.
Yes, very convoluted, and not portable out of Win32.
Have you tried this:

import dircache
dircache.listdir('.')

Re:If only (1)

Malevolyn (776946) | more than 6 years ago | (#21817380)

Well yeah, I picked that little snippet because it's a bunch of functions strung together. I can understand some people finding it a bit confusing, but any Python programming with real experience can look at the line I posted and know exactly what it does within a couple seconds. Well, unless they don't know what "dir" does. Even the popen code can be figured out in context.

Re:If only (1)

VGPowerlord (621254) | more than 6 years ago | (#21817480)

Well yeah, I picked that little snippet because it's a bunch of functions strung together. I can understand some people finding it a bit confusing, but any Python programming with real experience can look at the line I posted and know exactly what it does within a couple seconds. Well, unless they don't know what "dir" does. Even the popen code can be figured out in context.
...except that, from context, you weren't trying to give an example that Python programmers could understand...

Besides, chains like that work in most OO languages.

Re:If only (3, Funny)

theheadlessrabbit (1022587) | more than 6 years ago | (#21819410)

"I do love how beautiful the code looks no matter how convoluted you try and write it."

if code aesthetics are really important to you, they you really must go with basic.

10 CLS
20 PRINT "Hello world"
30 END

Look at the beautiful symmetry!
Look at the even row of numbers in one column, and how they prop up the commands sitting beside them.

I must say, BASIC code is truly an example of sublime beauty.
I pity the fool who codes in Python.

Re:If only (1)

Schraegstrichpunkt (931443) | more than 6 years ago | (#21821290)

raw = os.popen('dir /B').read().rstrip().split('\n')

Convoluted is exactly how I'd describe that horrible piece of buggy, platform-specific code that should be replaced by:

raw = os.listdir(".")

Re:If only (0)

Anonymous Coward | more than 6 years ago | (#21819036)

Python seems to be popular for plugins to some graphics programs. Maybe it could be used to animate virtual puppets in something such as Blender? (Would be cool for recording and choreographing movements if it can actually be worked out.)

Nigger-rigged-mote. (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21817180)

Nigmote for short.

Merry Christmas friends!

New Section Possibility (0)

Anonymous Coward | more than 6 years ago | (#21817986)

It seems everytime I log on here there's another article on wiimotes. It's probably time for a Wiimote section, sitting in between Games and Hardware. While you're at it, add one for all these future magic energy storage contraptions that pop up quite a bit.
Check for New Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...