findContours() error with cairo

asked 2013-05-31 09:13:48 -0500

updated 2013-05-31 09:19:41 -0500

berak gravatar image

Hi, I'm using Kinect with OpenCV 2.4.5 using freenect. Below is my code:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <libfreenect.h>
#include <pthread.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <iostream>

using namespace cv;
using namespace std;

Mat img_depth;
Mat img_rgb;
Mat img_temp;
Mat img_canny;
Mat img_canny_temp;

pthread_mutex_t mutex_depth = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_rgb = PTHREAD_MUTEX_INITIALIZER;
pthread_t cv_thread;

//callback for depthimage, called by libfreenect
void depthCallback(freenect_device *dev, void *depth, uint32_t timestamp)
    Mat depth8;
    Mat mydepth = Mat(Size(640, 480), CV_16UC1, depth);

    mydepth.convertTo(depth8, CV_8UC1, 1.0/4.0);
    memcpy(,, 640*480);

    //unlock mutex


//callback for rgbimage, called by libfreenect
void RGBCallback(freenect_device *dev, void *rgb, uint32_t timestamp)
    //lock mutex for opencv rgb image

    memcpy(, rgb, FREENECT_VIDEO_RGB_SIZE);

    //unlock mutex

 * thread for displaying the opencv content
void *cv_threadfunc(void *ptr)
    img_depth = Mat(Size(640, 480), CV_8UC1);
    img_rgb = Mat(Size(640, 480), CV_8UC3);
    img_temp = Mat(Size(640, 480), CV_8UC3);
    img_canny = Mat(Size(640, 480), CV_8UC1);
    img_canny_temp = Mat(Size(640, 480), CV_8UC1);

    //use image polling
        //lock mutex for depth image

        vector< vector<Point> > contours;

        Canny(img_depth, img_canny, 60, 110);

        findContours(img_canny, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

        imshow("Canny", img_canny);

        //unlock mutex for depth image

        //lock mutex for rgb image

        //show image to window

        imshow("Second", img_temp);

        //unlock mutex

        //wait for quit key
        if(cvWaitKey(15) == 27)


    return NULL;


int main(int argc, char **argv)
    freenect_context *f_ctx;
    freenect_device *f_dev;

    int res = 0;
    int die = 0;

    printf("Kinect camera test\n");

    if(freenect_init(&f_ctx, NULL) < 0)
        printf("freenect_init() failed\n");
        return 1;

    if(freenect_open_device(f_ctx, &f_dev, 0) < 0)
        printf("Could not open device\n");
        return 1;

    freenect_set_depth_callback(f_dev, depthCallback);
    freenect_set_video_callback(f_dev, RGBCallback);
    freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB);

    //create opencv display thread
    res = pthread_create(&cv_thread, NULL, cv_threadfunc, NULL);
        printf("pthread_create failed\n");
        return 1;

    printf("init done\n");


    while(!die && freenect_process_events(f_ctx) >= 0);

The error I'm getting is as follows:

/build/buildd/cairo-1.10.2/src/cairo-surface.c:1287: cairo_surface_set_device_offset: Assertion `status == CAIRO_STATUS_SUCCESS' failed. Aborted (core dumped)

I spent 5 hours on the internet searching for this, but still am clueless about this. Please help.

edit retag flag offensive close merge delete


i see a ton of code there, but nothing even vaguely related to cairo

berak gravatar imageberak ( 2013-05-31 09:26:26 -0500 )edit

As it turns out there was nothing wrong with my code. It was giving a problem just because my terminal always loads ROS bindings.

Siddharth Agrawal gravatar imageSiddharth Agrawal ( 2013-06-03 00:44:42 -0500 )edit

Hello Siddharth, I have the same problem when using OpenCV's findContours() function. However, I am using the OpenCV library in a ROS node, hence, I do require the ROS bindings. Any ideas how to fix the problem or what exactly causes the crash?

Thanks, Heiko

Huibuh gravatar imageHuibuh ( 2013-08-08 08:34:42 -0500 )edit