Ask Your Question

Fe++'s profile - activity

2020-02-04 02:21:11 -0500 received badge  Popular Question (source)
2018-03-12 11:51:06 -0500 received badge  Notable Question (source)
2016-10-29 05:56:36 -0500 received badge  Popular Question (source)
2014-12-26 08:14:41 -0500 asked a question Valid XML should start with '<?xml ...?>' in function icvXMLParse

I am reading the following yaml file, converted from the xml of pascal VOC 2007:

annotation:
  filename: 000001.jpg
  folder: VOC2007
  object:
  - bndbox: {xmax: '195', xmin: '48', ymax: '371', ymin: '240'}
    difficult: '0'
    name: dog
    pose: Left
    truncated: '1'
  - bndbox: {xmax: '352', xmin: '8', ymax: '498', ymin: '12'}
    difficult: '0'
    name: person
    pose: Left
    truncated: '1'
  owner: {flickrid: Fried Camels, name: Jinky the Fruit Bat}
  segmented: '0'
  size: {depth: '3', height: '500', width: '353'}
  source: {annotation: PASCAL VOC2007, database: The VOC2007 Database, flickrid: '341012865',
    image: flickr}

using

FileStorage fs(fName, FileStorage::READ);

I get this error:

OpenCV Error: Parsing error (/opt/Datasets/VOCdevkit_test/VOC2007/Annotations/000001.yml(1): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /home/alessandro/OpenCV/opencv-2.4.10.x-prep/modules/core/src/persistence.cpp, line 2252 terminate called after throwing an instance of 'cv::Exception' what(): /home/alessandro/OpenCV/opencv-2.4.10.x-prep/modules/core/src/persistence.cpp:2252: error: (-212) /opt/Datasets/VOCdevkit_test/VOC2007/Annotations/000001.yml(1): Valid XML should start with '<?xml ...?>' in function icvXMLParse

Aborted (core dumped) It is from an existing open source code that has worked in others settings. Does anyone idea of the problem? Is something related with OpenCv version? I am using 2.4.10

2014-10-27 10:37:23 -0500 asked a question Segmentation fault in pyopencv_from

I am implementing a function in cpp that needs to convert a Mat to a PyObject for being passed to Python as a Numpy array. Thus, I am stuck with a segmentation fault error in the m.copyTo(temp) call inside the function pyopencv_from that do the job. Looks like the g_roicropping_numpyAllocator cannot do the job. Here I past the code:

static PyObject* pyopencv_from(const Mat& m)

{
    if( !m.data )
        Py_RETURN_NONE;
    Mat temp, *p = (Mat*)&m;
    if(!p->refcount || p->allocator != &g_roicropping_numpyAllocator)
    {

    temp.allocator = &g_roicropping_numpyAllocator;

    m.copyTo(temp);
    p = &temp;
}

p->addref();

return pyObjectFromRefcount(p->refcount);

}

ROICropping::ROICropping(){
    import_array(); // This is a function from NumPy that MUST be called.
}

PyObject* ROICropping::crop(PyObject* image, PyObject* labels, int label){



//Release GIL
    ScopedGILRelease scoped;

    cv::Mat cv_image;
    cv::Mat cv_labels;

    pyopencv_to(image, cv_image);
    pyopencv_to(labels, cv_labels);

    cv::Size s = cv_image.size();

    cv::Mat mask(s.height,s.width,CV_8UC1, cv::Scalar::all(0));

    assert(cv_labels.type() == CV_16SC1);
    assert(cv_image.type() == CV_8UC3 || cv_image.type() == CV_8UC1);

    uint8_t *image_data = (uint8_t*) cv_image.data;
    int16_t *labels_data = (int16_t*) cv_labels.data;
    uint8_t *mask_data = (uint8_t*) mask.data;

    int32_t x0=s.width, x1=0, y0=s.height, y1=0;

    int32_t tmp_val, idx;
    for(int j = 0; j < cv_labels.rows; j++){
        for(int i = 0; i < cv_labels.cols; i++){
            idx = cv_labels.cols * j + i;
            tmp_val = labels_data[ idx ];
            if(label==tmp_val){
                mask_data[ idx ] = 1;

                if(j<x0){
                    x0 = j;
                }
                if(j>x1){
                    x1 = j;
                }
                if(i<y0){
                    y0 = i;
                }
                if(i>y1){
                    y1 = i;
                }
            }
        }
    }

    cv::Rect roi(x0, y0, x1-x0+1, y1-y0+1);

    cv::Mat crop_image(y1-y0+1, x1-x0+1, CV_8UC1);
    cv::Mat image_roi = cv_image(roi);
    crop_image = image_roi.clone();

    cv::Mat crop_mask(y1-y0+1, x1-x0+1, CV_8UC1);
    cv::Mat mask_roi = mask(roi);
    crop_mask = mask_roi.clone();

    PyObject *py_crop_image = pyopencv_from(crop_image);
    PyObject *py_crop_mask = pyopencv_from(crop_mask);

    return Py_BuildValue("(NN)", py_crop_image, py_crop_mask);
}
2014-10-01 10:07:08 -0500 commented answer pyopencv_from and pyopencv_to for KeyPoint class

Thanks, I was looking through there since a while. I will try to figure out what I need for transforming a cv::KeyPoint to a cv2.KeyPoint, attributes included.

2014-10-01 08:58:08 -0500 commented answer pyopencv_from and pyopencv_to for KeyPoint class

Yes, I have been working on it but still I cannot figure out few things. During compilation time some other c++ code is produced and contains certain functione, such as pyopencv_from and pyopencv_to for KeyPoint. I have managed to transform vector of KeyPoint from C++ to Python by using pyopencv_from generated in release/modules/python/pyopencv_generated_types.h. However, the KeyPoint object that I have wrapped in Python do not have any of its correct attribute. I have found out also where getter and setter method are implemented. However, it is like I am missing the declaration of the PyObject attributes, and I do not have a clue on how and where this is done in OpenCV wrapping process.

2014-10-01 08:20:24 -0500 received badge  Supporter (source)
2014-10-01 08:19:54 -0500 commented answer pyopencv_from and pyopencv_to for KeyPoint class

Thanks, really helpfull. Still, do you know how to manage the conversion of keypoint from cpp to python? I would like to exploit also GPU SIFT by using python, and I need the same conversion. What technology is used for generating python opencv wrapper?

2014-10-01 08:17:01 -0500 received badge  Scholar (source)
2014-09-30 08:54:42 -0500 asked a question pyopencv_from and pyopencv_to for KeyPoint class

Since Bag of Words is not wrapped in Python, I need to do the work in Cpp function and pass the results through libboost interface. Still, I cannot figure out how a KeyPoint class is transformed to a PyObject* and viceversa. Is there any pyopencv_from and pyopencv_to method for that? Thanks.

2013-05-16 06:06:16 -0500 received badge  Student (source)
2013-05-16 03:01:21 -0500 asked a question parallel_for in Python bindings

Is there any way to exploit parallel_for binding by means of python bindings?