Go to Post Without compromise, engineering would be boring. - Mike Betts [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 20-01-2014, 18:48
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kinect

The Kinect is a nice sensor, which has an IR projector, an IR camera and an BGR camera. The IR projector and camera work together to for depth perception because as you go further away, the IR projector's IR dots will be much more scattered. The Kinect also has some great hardware, and is quite competitively priced for what it's got.

Today, when I was hacking around with the Kinect, in Robotics, I learned quite a bit of stuff, and I also got some areas where I need some help and assistance.

So for the software I used, I installed Ubuntu using Wubi (though you can do so any way). After that finished installing, I updated and upgraded the system, so it was running like a hungry lion! I installed some software with the following command:
sudo apt-get install qtcreator pkg-config libopencv-dev python-opencv libfreenect-dev libfreenect-demos chromium-browser flashplugin-installer
That installed a lot of stuff and took about half an hour on our school's wifi (very fast). By the way, skip the last two because that installs a browser and the adobe flash plugin for Firefox/chromium.

So I then blacklisted the Kinect, so it would be accessible to the system.

I was able to successfully run some sample programs, downloaded using apt-get:
freenect-glview

However, I am unable to compile any libfreenect source code! I am using QT Creator as the C++ IDE.

So, I ran pkg-config libfreenect --libs, and got the output I was looking for, so I was able to use it in the project file for QT Creator. However, even though I included the libfreenect.hpp, the which showed up as a valid file, I kept getting random errors every time I tried to compile code.

What did I do wrong, and how could I fix it? Does anyone have some sample code to interface the Kinect, libfreenect with OpenCV for the image processing? I just want to exploit the infrared camera that is in the Kinect! OpenCV can do the rest.
  #2   Spotlight this post!  
Unread 20-01-2014, 19:12
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,756
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Compilers shouldn't really give random errors. They are almost guaranteed to return errors which are hard for people to understand, and small changes in a #include or a build setting can lead to very different errors.

Perhaps this would be easier if you were to include some of those error messages.

Greg McKaskle
  #3   Spotlight this post!  
Unread 20-01-2014, 19:26
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

I'll try to take screenshots/videos/etc. to show what's going on
  #4   Spotlight this post!  
Unread 20-01-2014, 19:38
faust1706's Avatar
faust1706 faust1706 is offline
Registered User
FRC #1706 (Ratchet Rockers)
Team Role: College Student
 
Join Date: Apr 2012
Rookie Year: 2011
Location: St Louis
Posts: 498
faust1706 is infamous around these partsfaust1706 is infamous around these parts
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Shot in the dark: you didn't set up up the gcc as the c++ compiler.

http://ratchetrockers1706.org/vision-setup/
__________________
"You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."
  #5   Spotlight this post!  
Unread 20-01-2014, 19:41
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Quote:
Originally Posted by faust1706 View Post
Shot in the dark: you didn't set up up the gcc as the c++ compiler.

http://ratchetrockers1706.org/vision-setup/
LOL. That might be it. However, why did OpenCV work, then? That's kinda wierd! Let me tweak those settings and report back! I need to write a whitepaper about this once I'm done, so rookies don't fall into the same hole as I!
  #6   Spotlight this post!  
Unread 21-01-2014, 00:11
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

OK. So I did change some compiler settings, and create a new project. However, I'm still unable to compile with libfreenect. I did get rid of all the errors that libfreenect gave me, until my compiler gave me 3000+ errors !

I think it was because I was trying out some C code, and the setup was really a mix of both C and C++! Bad me

I need to now work on porting this IplImage and CvArr stuff to CvCapture and Mat!
  #7   Spotlight this post!  
Unread 21-01-2014, 11:23
faust1706's Avatar
faust1706 faust1706 is offline
Registered User
FRC #1706 (Ratchet Rockers)
Team Role: College Student
 
Join Date: Apr 2012
Rookie Year: 2011
Location: St Louis
Posts: 498
faust1706 is infamous around these partsfaust1706 is infamous around these parts
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Do you have the namespaces cv and or std?

You can just put mat img = cvcapture() I think. I'm on my phone so I apologize if my capitalization isn't proper for functions.

Look into cvqueryframe. That is one I have used in the past and you can save the output as a mat.
__________________
"You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."
  #8   Spotlight this post!  
Unread 21-01-2014, 11:51
MoosingIn3space MoosingIn3space is offline
Programming Division Captain
FRC #3334 (Eagle Robotics)
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Salt Lake City, UT
Posts: 13
MoosingIn3space is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

I have attached my sample code for my school's KinectDevice class, written in C++, which provides a simple interface to the Kinect. You simply write
Code:
// assuming 'capture' is a KinectDevice
cv::Mat frame;
capture >> frame;
in order to read a frame from the Kinect. Hope it helps.
Attached Files
File Type: hpp freenecthelper.hpp (891 Bytes, 43 views)
File Type: cpp freenecthelper.cpp (920 Bytes, 54 views)
  #9   Spotlight this post!  
Unread 21-01-2014, 20:16
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

This is the problem I am facing (below)
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2014-01-21 18:14:58.png
Views:	89
Size:	228.4 KB
ID:	15905  Click image for larger version

Name:	Screenshot from 2014-01-21 18:16:26.png
Views:	53
Size:	271.1 KB
ID:	15906  
  #10   Spotlight this post!  
Unread 21-01-2014, 21:42
faust1706's Avatar
faust1706 faust1706 is offline
Registered User
FRC #1706 (Ratchet Rockers)
Team Role: College Student
 
Join Date: Apr 2012
Rookie Year: 2011
Location: St Louis
Posts: 498
faust1706 is infamous around these partsfaust1706 is infamous around these parts
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Will you (attempt) to compile through terminal? It _should_ give a more detail error. More to work with.


make clean
make
./(executable name) will execute the program

In case you don't know of forgot
__________________
"You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."
  #11   Spotlight this post!  
Unread 21-01-2014, 22:05
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Here's the output:
rm -f main.o
rm -f *~ core *.core
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../TestOpenCVLibFreenect -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../TestOpenCVLibFreenect -I. -o main.o ../TestOpenCVLibFreenect/main.cpp
g++ -Wl,-O1 -o TestOpenCVLibFreenect main.o -L/usr/lib/x86_64-linux-gnu `pkg-config opencv --libs` libfreenect --libs` -lQtCore -lpthread

Sadly, I don't speak robot (or do I?) so I don't really understand what the problem is!
  #12   Spotlight this post!  
Unread 21-01-2014, 22:31
POSIXGuru POSIXGuru is offline
Registered User
FRC #1389 (The Body Electric)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Walt Whitman High School
Posts: 3
POSIXGuru is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Try changing `pkg-config opencv --libs` libfreenect --libs` to `pkg-config --libs opencv libfreenect`

Quote:
Originally Posted by yash101 View Post
Here's the output:
rm -f main.o
rm -f *~ core *.core
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../TestOpenCVLibFreenect -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../TestOpenCVLibFreenect -I. -o main.o ../TestOpenCVLibFreenect/main.cpp
g++ -Wl,-O1 -o TestOpenCVLibFreenect main.o -L/usr/lib/x86_64-linux-gnu `pkg-config opencv --libs` libfreenect --libs` -lQtCore -lpthread

Sadly, I don't speak robot (or do I?) so I don't really understand what the problem is!
  #13   Spotlight this post!  
Unread 21-01-2014, 22:39
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

I'm still getting a same/similar error. I am starting to feel as though it is the library, libfreenect, that is doing this! OpenCV still works, and my code is so modular, you change a viariable, it uses an MGPEG stream or an internal camera! That's how I know that the code works!
  #14   Spotlight this post!  
Unread 22-01-2014, 00:53
faust1706's Avatar
faust1706 faust1706 is offline
Registered User
FRC #1706 (Ratchet Rockers)
Team Role: College Student
 
Join Date: Apr 2012
Rookie Year: 2011
Location: St Louis
Posts: 498
faust1706 is infamous around these partsfaust1706 is infamous around these parts
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

wait. Did you try running the program in terminal?
__________________
"You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."
  #15   Spotlight this post!  
Unread 22-01-2014, 19:30
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Getting the Kinect to work with OpenCV and libfreenect/My experience with the Kin

Ya. I ran it in Terminal and I think I pasted the output above and PMed it to you.

I'll try to fresh-install Ubuntu, and install OpenCV and libfreenect a better way. I guess I can say that the instructions on the getting started page are broken, so how do y'all suggest I install libfreenect? Any links to tutorials would be appreciated! Also, what version of Ubuntu should I target? The problem could be because I am not using the latest version of Ubuntu (I'm using what's available through Wubi!)

I'll also try to document the process and start working on my whitepaper!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi