compile cvdemo.c with oppopenKinect-libfreenect-bdd9219 wrapper -> opencv

417 views
Skip to first unread message

nomad

unread,
Jan 5, 2011, 4:42:38 AM1/5/11
to OpenKinect
hi,
when i compile cvdemo.c with this
Makefile:
--------------
all: cvdemo

CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
INCLUDE = -I/usr/local/include/libfreenect
FREE_LIBS = -L/usr/local/lib -lfreenect

cvdemo: cvdemo.c
$(CXX) $(INCUDE) $(CFLAGS) $? -o $@ $(LIBS) $(FREE_LIBS)

%.o: %.c
$(CXX) -c $(CFLAGS) $< -o $@

clean:
rm -rf *.o cvdemo
-------------------------------------------------
failures:
------------------------------------------------
/tmp/ccMVJhAR.o: In function `main':
/home/nomad/cvKINECTS_4/OpenKinect-libfreenect-bdd9219/wrappers/opencv/
cvdemo.c:59: undefined reference to `freenect_sync_get_rgb_cv'
/home/nomad/cvKINECTS_4/OpenKinect-libfreenect-bdd9219/wrappers/opencv/
cvdemo.c:65: undefined reference to `freenect_sync_get_depth_cv'
collect2: ld returned 1 exit status
make: *** [cvdemo] Fehler 1
------------------------------------------------
i think, that wrapper/opencv/ are not uptodate:
please i you make a new release then please make a update for opencv
or
have you tip for me to compile cvdemo.c
my makefile is ok i can compile my stuff
or
give me some hints how i can compile ->wrapper/opencv -> cvdemo.c with
your cmake....
thanks for the help
regards nomad

AK

unread,
Jan 26, 2011, 9:24:00 AM1/26/11
to OpenKinect
Hi,
I am also stuck with the same problem.. First of all I think you
also need to compile libfreenect_cv.c and include the compilation
instruction in the makefile and then you need to link
libfreenect_sync.so as well in usr/lib or /usr/local/lib...Please
reply on this as I need to get the code running soon to move forward
in the project...

nomad

unread,
Jan 26, 2011, 10:49:13 AM1/26/11
to OpenKinect
hi,
excuse for your stuck and your problem.
i wrote this posting on 5.january
in the meantime i have develop my own stuff for opencv and libfreenect
if you want , i can send a attachment for you but i dont know your
libfreenect-release.

for glview.c -> compile with
cc -fPIC -g -Wall glview.c -o glview -I/usr/X121R6/include -I../libusb/
libusb/libusb-1.0 -I/usr/local/include/libfreenect -L/usr/X121R6/lib -
L/usr/local/lib64 -lfreenect -lglut -lGLU -lGL -lm

for opencv & libfreenect:
----------------------------------
//
===========================================================================================//
// cvOpenKinectContour2.cpp
// ------------------------
//
// begin : Sun. 09. January 14.00:00 GMT
2010
// copyright : (C) 2008/2009/2010 by s.morf
// email : steve...@bluewin.ch
// originalCompile with
// opencv
// g++ -fPIC -g -Wall -I/usr/local/include/opencv -L /usr/local/
lib -lcxcore -lcv -lhighgui -lcvaux -lml -o cvOpenKinectContour2
cvOpenKinectContour2.cpp -lfreenect -lm

// run as : ./cvOpenKinectContour2
// Basics of : - interduction to compile opencv with libfreenect
*************************************************************************************************
NOTES:
04.01.2010
04.01. - interductions compile opencv program mit Kinect (libfreenect)
Unterstuetzung
- 1) compile cvColor1.cpp only opencv
- cvColor1.cpp kann hier compiliert werden OK
- 2) es geht darum test.cpp mit libfreenect & opencv
unterstuetzung zu compilieren
- fuer test.cpp steht ein Makefile zur verfuegung
- compile with Makefile OOK
- Run OK
05.01. - 1.versuche eigenes opencv-prog zu entwickeln:
- test1.cpp is a clone of test.cpp
- test.cpp with make (hat die komische angewohntheit) with
esc not exit bleibt haengen
- test1.cpp kann auf der console mit dem output von make
compiliert werden run ok
- hat die selbe angewohnheit
- test1.cpp kann aber auch mit meinem eigen compile
compiliert werden also:
--> g++ -fPIC -g -Wall -I/usr/local/include/opencv -L /
usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml -o
cvOpenKinectContour2 cvOpenKinectContour2.cpp -lfreenect -lm
- compile and run OK
- 2) kann jetzt ein frame "result.jpg" ins folder schreiben
und dann "result.jpg in einem eigenen fenster ansehen
06.01. - weitere versuche:
- basic are cvBodyTracking10.cpp
- nach sehr vielen irrungen einbau von
- 1) - colorDetections();
- und output "result.jpg"
- run ok
- 2) - BodyContours() (1) einbau
- 1.run OK 1.video gemacht
- troubles bei abbruch esc
- bei youTube angemeldet und video raufgeladen
- 3) - BodyTrackCalc() zeigt jetzt (x,y)-Pos of
handDetections
- entspricht jetzt im grossen und ganzen
cvBodyTracking10.cpp
- probleme:
- bei abbruch exc muss noch gekillt werden
- zuviele windows es muessten eigentlich nur 2
windows sein
- 1) tracking
- 2) depth gray-values

references:
cv::Mat img1 = cv::imread("image.jpg",1);
cv::namedWindow("My Window", CV_WINDOW_AUTOSIZE);
cv::imshow("My Window", img1);
liest image.jpg ein und zeigt es in window anerzeugt

**************************************************************************************************************/
#include "libfreenect.hpp"
#include <iostream>
#include <vector>
#include <cmath>
#include <pthread.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <stdio.h>
#include <string.h>

//Some defines we left out of the book
#define CVX_RED CV_RGB(0xff,0x00,0x00)
#define CVX_GREEN CV_RGB(0x00,0xff,0x00)
#define CVX_BLUE CV_RGB(0x00,0x00,0xff)

// from ex-8-2.c
IplImage* g_image = NULL;
IplImage* g_gray = NULL;
int g_thresh = 100;
CvMemStorage* g_storage = NULL;

using namespace cv;
using namespace std;

// dirty stuff for esc=exit
pthread_t freenect_thread;
/
************************************************************************************************************/
class Mutex {
public:
Mutex() {
pthread_mutex_init( &m_mutex, NULL );
}
void lock() {
pthread_mutex_lock( &m_mutex );
}
void unlock() {
pthread_mutex_unlock( &m_mutex );
}
private:
pthread_mutex_t m_mutex;
};
/
************************************************************************************************************/
class MyFreenectDevice : public Freenect::FreenectDevice {
public:
MyFreenectDevice(freenect_context *_ctx, int _index)
: Freenect::FreenectDevice(_ctx, _index),
m_buffer_depth(FREENECT_DEPTH_11BIT_SIZE),m_buffer_rgb(FREENECT_VIDEO_RGB_SIZE),
m_gamma(2048), m_new_rgb_frame(false), m_new_depth_frame(false),
depthMat(Size(640,480),CV_16UC1),
rgbMat(Size(640,480),CV_8UC3,Scalar(0)),
ownMat(Size(640,480),CV_8UC3,Scalar(0))
{
for( unsigned int i = 0 ; i < 2048 ; i++) {
float v = i/2048.0;
v = std::pow(v, 3)* 6;
m_gamma[i] = v*6*256;
}
}
// Do not call directly even in child
void VideoCallback(void* _rgb, uint32_t timestamp) {
std::cout << "RGB callback" << std::endl;
m_rgb_mutex.lock();
uint8_t* rgb = static_cast<uint8_t*>(_rgb);
rgbMat.data = rgb;
m_new_rgb_frame = true;
m_rgb_mutex.unlock();
};
// Do not call directly even in child
void DepthCallback(void* _depth, uint32_t timestamp) {
std::cout << "Depth callback" << std::endl;
m_depth_mutex.lock();
uint16_t* depth = static_cast<uint16_t*>(_depth);
depthMat.data = (uchar*) depth;
m_new_depth_frame = true;
m_depth_mutex.unlock();
}

bool getVideo(Mat& output) {
m_rgb_mutex.lock();
if(m_new_rgb_frame) {
cv::cvtColor(rgbMat, output, CV_RGB2BGR);
m_new_rgb_frame = false;
m_rgb_mutex.unlock();
return true;
} else {
m_rgb_mutex.unlock();
return false;
}
}

bool getDepth(Mat& output) {
m_depth_mutex.lock();
if(m_new_depth_frame) {
depthMat.copyTo(output);
m_new_depth_frame = false;
m_depth_mutex.unlock();
return true;
} else {
m_depth_mutex.unlock();
return false;
}
}

private:
// new stuff boo-stuff before Mat-stuff no warnings compile and run
OK
std::vector<uint8_t> m_buffer_depth;
std::vector<uint8_t> m_buffer_rgb;
std::vector<uint16_t> m_gamma;

bool m_new_rgb_frame;
bool m_new_depth_frame;

Mat depthMat;
Mat rgbMat;
Mat ownMat;
Mutex m_rgb_mutex;
Mutex m_depth_mutex;
};
/*******************************************************************/
void on_trackbar(int)
{
if( g_storage == NULL)
{
g_gray = cvCreateImage( cvGetSize( g_image ), 8, 1 );
g_storage = cvCreateMemStorage(0);
}
else
{
cvClearMemStorage( g_storage );
}

CvSeq* contours = 0;
cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );

cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );

if( contours )
{
cvDrawContours( g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100
);

cvShowImage( "DEPTH", g_gray );
}
}
/*******************************************************************/
int main(int argc, char **argv)
{
bool die(false);
string filename("snapshot");
string suffix(".png");
int iter(0);

IplImage *frame;

Mat depthMat(Size(640,480),CV_16UC1);
Mat depthf (Size(640,480),CV_8UC1);
Mat rgbMat(Size(640,480),CV_8UC3,Scalar(0));
Mat ownMat(Size(640,480),CV_8UC3,Scalar(0));

Freenect::Freenect<MyFreenectDevice> freenect;
MyFreenectDevice& device = freenect.createDevice(0);

// lesen
// cv::Mat img1 = cv::imread("of_image.jpg",1);

//new windowScreenPosition ok
cvNamedWindow("RGB",CV_WINDOW_AUTOSIZE);
cvMoveWindow("RGB", 0, 0);

cvNamedWindow("DEPTH",CV_WINDOW_AUTOSIZE);
cvMoveWindow("DEPTH", 700, 0 );

device.startVideo();
device.startDepth();

while(!die)
{
device.getVideo(rgbMat);
device.getVideo(ownMat);
device.getDepth(depthMat);

// original
cv::imshow("RGB", rgbMat);
//cv::imshow("rgb",frame);
// save output for colorDetections()
cv::imwrite("originalRGB.jpg",rgbMat);

// schreiben ist jetzt in folder vorhanden
//
cv::imwrite("result.jpg",rgbMat);//,CV_IMWRITE_JPEG_QUALITY);
// lesen
cv::Mat img1 = cv::imread("original.jpg",1);

// cv::imshow("myWindow",img1);

// zuweisung iplImage Frame for Colordetections
frame = cvLoadImage("original.jpg", 1);

depthMat.convertTo(depthf, CV_8UC1, 255.0/2048.0);
// cv::imshow("DEPTH",depthf);

// save origDepth.jpg
cv::imwrite("originalDepth.jpg",depthf);

// from ex-8-2.c
g_image = cvLoadImage("originalDepth.jpg",1);

cvCreateTrackbar( "Threshold",
"DEPTH",
&g_thresh,
255,
on_trackbar
);

int key;

key = cvWaitKey(10) & 0xFF;

if(key == 27) // ESC
{
die = true;
cvDestroyWindow("rgb");
cvDestroyWindow("depth");

// here zwischen loesung fuer esc == exit
pthread_join(freenect_thread, NULL);
pthread_exit(NULL);
break;
}
iter++;
}

device.stopVideo();
device.stopDepth();

return 0;
}
---------------------------------

hope it's helpful
regards nomad

AK

unread,
Jan 26, 2011, 1:33:09 PM1/26/11
to OpenKinect
Hey thanks nomad for the tip. But I couldnt get it totally from your
code..Maybe it will be help if you can mail me your code as a tarball.
I did not get most of the comments as I am not familiar with the
language...I am taking the release staight from github. So its the
latest version I guess...Thanks in advance...
ID - abhi....@gmail.com

AK

On Jan 26, 8:49 pm, nomad <stevenm...@bluewin.ch> wrote:
> hi,
> excuse for your stuck and your problem.
> i wrote this posting on 5.january
> in the meantime i have develop my own stuff for opencv and libfreenect
> if you want , i can send a attachment for you but i dont know your
> libfreenect-release.
>
> for glview.c -> compile with
> cc -fPIC -g -Wall glview.c -o glview -I/usr/X121R6/include -I../libusb/
> libusb/libusb-1.0 -I/usr/local/include/libfreenect -L/usr/X121R6/lib -
> L/usr/local/lib64 -lfreenect -lglut -lGLU -lGL -lm
>
> for opencv & libfreenect:
> ----------------------------------
> //
> =========================================================================== ================//
> //     cvOpenKinectContour2.cpp
> //     ------------------------
> //
> //     begin     : Sun. 09. January 14.00:00 GMT
> 2010
> //     copyright : (C) 2008/2009/2010 by  s.morf
> //     email     : stevenm...@bluewin.ch
>                  cvDestroyWindow("rgb");...
>
> read more »

nomad

unread,
Jan 28, 2011, 3:21:13 AM1/28/11
to OpenKinect
hi
today i have send your a mail with the source-code "test.cpp" with
compile-instructions
excuse my comments in the above code on german:
i hope its useful for you
regards nomad

On Jan 26, 7:33 pm, AK <abhi.gu...@gmail.com> wrote:
> Hey thanks nomad for the tip. But I couldnt get it totally from your
> code..Maybe it will be help if you can mail me your code as a tarball.
> I did not get most of the comments as I am not familiar with the
> language...I am taking the release staight from github. So its the
> latest version I guess...Thanks in advance...
> ID - abhi.gu...@gmail.com

Saúl

unread,
Mar 15, 2011, 4:55:58 PM3/15/11
to OpenKinect
You can compile it using pkg-config, like that:
gcc `pkg-config --cflags --libs opencv libfreenect` -lfreenect_cv -o
cvdemo cvdemo.c

or the "long" way:
gcc -I/usr/local/include/libfreenect -I/usr/local/include/opencv -I/
usr/include/libusb-1.0 -L/usr/local/lib64 -L/usr/local/lib -lml -
lcvaux -lhighgui -lcv -lcxcore -lfreenect -lusb-1.0 -lfreenect_cv -o
cvdemo cvdemo.c
> ...
>
> leer más »

Saúl

unread,
Mar 15, 2011, 4:55:45 PM3/15/11
to OpenKinect
You can compile it using pkg-config, like that:
gcc `pkg-config --cflags --libs opencv libfreenect` -lfreenect_cv -o
cvdemo cvdemo.c

or the "long" way:
gcc -I/usr/local/include/libfreenect -I/usr/local/include/opencv -I/
usr/include/libusb-1.0 -L/usr/local/lib64 -L/usr/local/lib -lml -
lcvaux -lhighgui -lcv -lcxcore -lfreenect -lusb-1.0 -lfreenect_cv -o
cvdemo cvdemo.c

On 28 ene, 02:21, nomad <stevenm...@bluewin.ch> wrote:
> ...
>
> leer más »
Reply all
Reply to author
Forward
0 new messages