In an earlier post I explained how to get PrimeSense's NITE up and running and how to use the samples they provided. Now some people might be thinking "cool, but how can I use this?" I thought using NITE hand tracking to control the cursor would be a good and simple demonstration.
The linux kernel provides a means to create userspace input drivers using a feature called uinput. If you compile your kernel with uinput enabled as a module you can then simply:
modprobe uinput
to load the uinput module. Once the module is loaded you can use the piece of code I've embedded below to convert the coordinates output by the NITE code into actual mouse/cursor movement. In short:
(1) download the code below
(2) save it as ~/kinect/NITE/Nite-1.3.0.17/Samples/SingleControl/main.cpp (you might want to back up the original)
(3)
cd ~/kinect/NITE/Nite-1.3.0.17 && make
(4)Note: do the following as root or using sudo
~/kinect/NITE/Nite-1.3.0.17/Samples/Bin/Sample-SingleControl
(5)Perform a focus gesture to start the hand tracking (check out my video above to see how to do that)
At this point you should be able to do what I do in the video above. You can also extend the code to generate mouse clicks, keystrokes, etc. Have fun.
At some point dropbox ate the public link for the source code I was using before and in the process of restoring from an old backup the formatting of the code below got a bit mangled... in any case here's a gist of what I salvaged:
Hi,
ReplyDeleteI think I've ported the essence of your implementation on Windows without synergy.
~~~~~~~~~~~~~~~~
#include conio.h
#define WIN32_LEAN_AND_MEAN // Exclude Extra Windows Crap
#define WIN32_EXTRA_LEAN // Exclude More Windows Crap
#include windows.h
~~~~~~~~~
void XN_CALLBACK_TYPE OnPointUpdate(const XnVHandPointContext* pContext, void* cxt)
{
//printf("%d: (%f,%f,%f) [%f]\n", pContext->nID, pContext->ptPosition.X, pContext->ptPosition.Y, pContext->ptPosition.Z, pContext->fTime);
printf("%d: (%f,%f,%f) [%f]\n", pContext->nID, pContext->ptPosition.X*2.5, pContext->ptPosition.Y*2.5, pContext->ptPosition.Z, pContext->fTime);
SetCursorPos((int)(pContext->ptPosition.X*2.5),(int) -(pContext->ptPosition.Y*2.5));
}
~~~~~~~~~~~~~~~~~~~~~~
Then you'd change constant 2.5 depending on resolution and sensitivity.
Thanks for keeping your code open so other people can use it.
Hi, have you figured out by now how to do multiple hand tracking?
ReplyDeleteFirstname, yeah, I was trying to throw together some code using multipointer X to demonstrate it, but for now I'll just add a mention of the config file change that's needed and the contents of an XnHandPointContext.
ReplyDeleteHello,
ReplyDeleteIs there any way that works on windows?
Hey trtg,
ReplyDeleteDo you have a public email address for this blog that I could reach you at?
Jared, try the "Contact me" form at the bottom of each page. Please be aware,however, that if you have some lengthy support request, I probably won't be able to help you. I do not work for Primesense or any other related company and only have limited time to dedicate to this blog.
ReplyDeletewhen i run (4)~/kinect/NITE/Nite-1.3.0.17/Samples/Bin/Sample-SingleControl
ReplyDeleteit says illegal construction. whats wrong with it?
For the illegal instruction issue, try running the program under gdb to locate the source of the illegal instruction call.
ReplyDeleteIf it comes from libXnVFeatures or libXnVHandGenerator try downloading the newest unstable Nite build from http://www.openni.org/downloadfiles/openni-compliant-middleware-binaries/33-latest-unstable.
I had an issue regarding illegal opcodes and my AMD x86_64 processor. The new Nite build seemed to resolve it.
Is there anyway I can see if I have uinput compiled in my kernel and enabled as a module on my system.
ReplyDeleteI'm running Mint Linux 9
Cheers!
Jeff,
ReplyDeleteThe most straightforward way would be to simply try running (as root):
modprobe uinput
If that command fails, uinput probably wasn't enabled in your kernel. If the output of modprobe somehow wasn't clear enough you can try running the command:
modinfo uinput
If the uinput module is present on your system you should see a bunch of info. More directly you can try
lsmod | grep uinput
to check whether the uinput module is already loaded.
It runs, outputs the hand coordinates in terminal, however mouse doesnt move. I have uinput and did modprobe, but nothing seems to happen. There are no error messages either
ReplyDeleteThe problem seems to be basically the same as :
ReplyDeletehttp://ubuntuforums.org/showthread.php?t=1617581
Mike, I forgot to mention in my original post that unless you've set up permissions so that your user has full access to /dev/uinput you will need to run Sample-SingleControl as root. This may resolve your issue.
ReplyDeleteWait is there a way to click on this?
ReplyDeleteHi
ReplyDeletewhenever i try run this it throw me this error Couldn't initialize: File not found!
:( even i run it as su
@uahmed: there should be a line somewhere in the main.cpp that looks like this:
ReplyDelete#define SAMPLE_XML_FILE "Data/Sample-Tracking.xml"
Make sure that Sample-Tracking.xml is in the correct place relative to the working directory, otherwise the program won't be able to set up the module.
@trtg: trying to get clicking to work properly - I figured it would be something like:
void click_mouse()
{
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = BTN_MOUSE;
event.value = BTN_LEFT;
write(uinp_fd, &event, sizeof(event));
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(uinp_fd, &event, sizeof(event));
}
Probably going to use two hands, one for clicking and one for moving the cursor (for this I'll cannibalise the PointViewer example). Thanks for the howtos - they've been really helpful!
ok great :)
ReplyDeleteburberry outlet canada
ReplyDeleteralph lauren sale clearance
oakley sunglasses
coach factory outlet
adidas yeezy
ralph lauren outlet
pandora sale
cheap jordans
ed hardy clothing
michael kors outlet
20170323huazhen
ray ban sunglasses
ReplyDeletecoach outlet
tory burch
oakley sunglasses
christian louboutin
nike store
yeezy boost 350 v2
michael jordan shoes
coach outlet
red bottom shoes
20175.6wengdongdong
ray ban sunglasses
ReplyDeletemichael kors outlet
michael kors outlet
nike air max
coach outlet
adidas yeezy
tods outlet
pandora outlet
discount oakley sunglasses
michael kors canada
mt0622
burberry outlet store
ReplyDeletemichael kors outlet store
cazal outlet
christian louboutin outlet
nike air huarache
cheap oakley sunglasses
vans outlet
christian louboutin sale
coach outlet
coach outlet
chanyuan2017.06.30
20180102 leilei3915
ReplyDeletepolo outlet
jordan shoes
kate spade outlet online
coach factory outlet
ugg outlet store
christian louboutin
ray ban sunglasse
michael kors outlet online
cheap jordans for sale
ralph lauren shirts
It is effectively swelled and has a no slip wellbeing playing surface and it helps your cover, so you don't destroy your cover from playing Kinect diversions. Renars
ReplyDeleteThis baby needs to stay cool at all costs or it's the Red Rings of Death for You. Now with this and the use of proper Xbox live gold gratis
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSo as to sell pretending games you need a group of people willing to purchase the item and if an organization reliably puts out dodgy shooters in the appearance of evident pretending games they'll just decimate their notoriety and go bankrupt.https://unblockedgamez800.weebly.com
ReplyDeleteCoach Handbags Outlet are usually viewed as luxurious brands, but yet at inexpensive price.
ReplyDeleteToday most people looking for COACH accessories will look for them at Coach Bags Factory Outlet.
Coach Sale are just the most inexpensive items to purchase through Coach Purses Outlet, a small change purse or Cheap Coach Purses.
Coach Bags On Sale are a fun accessory to add to a new collection.
Coach Bags Outlet is can be carried or slipped over your shoulder.
Authentic MK Outlet are made of high grade quality leather and Michael Kors Factory Outlet can actually have real leather on them.
Michael Kors Purse Sale usually come with a plate bearing the MK Outlet logo to distinguish it from other Cheap Michael Kors Purses.
Michael Kors Outlet Online have the inherent ability to capture the essence of what women like and what they want to wear and utilize.
Michael Kors Outlet Store are a symbol of feminine elements and speak for all kinds of women.
Michael Kors Purses On Sale of the day vary greatly, but all seem to share one characteristic, they are popular!
Coach Outlet Usa
ReplyDeleteCoach Bags Outlet
Coach Sale
Coach Outlet Sale
Coach Bags For Cheap
Coach Bags On Sale At Outlet
Coach Outlet Near Me
Coach Name Change
Coach Store
Coach Tote
Black Coach Purse
Outlet Michael Kors
MK Purses Clearance
Michael Kors Outlet Sale
Michael Kors Bags On Sale Amazon
Amazon Michael Kors Bags
Michael Kors Tote Sale
Cheap MK Bags
MK Handbags Sale
Michael Kors Outlet Online
MK Bags On Sale
Cheap Michael Kors
Cheap Michael Kors Handbags
Both things are possible if you carry Michael Kors Handbags Wholesale. If you are a woman who goes for innovative designs, a designer Michael Kors Bags On Sale is perfect for you. Offering a huge selection of chic purses, handbags, shoes and accessories, Michael Kors Outlet Online Store celebrates womanhood in an entirely unique way. Michael Kors Factory Outlet Online Store At Wholesale Price are one of the most sought-after handbags worldwide. We all agree that diamonds are a woman's best friend; however Official Coach Factory Outlet Online are absolutely next in line. To Coach Outlet Sale aficionados, don't fret because we have great news: a discount Official Coach Outlet Online isn't hard to find. If you are a smart shopper looking for a good buy and great deals on your next handbag purchase, you can go to Official Coach Outlet Online.
ReplyDeleteFriendly Links: Toms Shoes Womens | Toms Clearance
khasiat dari obat tersebut bisa memberikan manfaat pada pasutri yang ingin mendapatkan kepuasan dalam bercinta agar kedua pasangan semakin harmonis ketika bercinta. bagi anda yang ingin mendapatkan viagra asli bisa anda beli diberbagai tempat asal sudah terbukti dengan keaslian produk dengan cara mengenali viagra usa asli pfizer 100 mg langsung dari berbagai situs yang sudah terpercaya atau dari refrensi teman yang sudah menggunakan viagra asli usa pfizer 100 mg silahkan anda berkunjung kesitus resmi agen yang ada diindonesia dan yang secara resmi menjadi agen distributor viagra asli usa 100 mg sejak tahun 1995 sampai sekarang. klik disini . selanjutnya ada produk dari amerika lainnya yang sangat terkenal baru-baru ini yaitu vimax asli berkhasiat untuk ereksi dan untuk memperbesar alat vital pria secara permanen berguna untuk memaksimalkan kepuasan saat diranjang.
ReplyDeleteIndependent Escorts in Dubai is the right decision. the top Dubai Escorts at your one Click. Log on to us for entertainment.
ReplyDelete충주출장샵
ReplyDelete청주출장샵
원주출장샵
예산출장샵
원주출장샵
총판출장샵
총판출장샵
광양출장안마
ReplyDelete광양출장안마
상주출장안마
진안출장안마
상주출장안마
전북출장안마
전북출장안마