Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

your returned Mat from extract_features_mat() is invalid.

if you construct a Mat with a "borrowed" data pointer, it is just doing a "shallow" copy, only the pointer gets copiied, not the data, so once the original pointer gets out of scope (because it is local, and you return from the function), you got a "dangling" pointer.

try :

return Mat(1,feature_size, CV_64FC1, feature_value).clone() ;

to achieve a "deep" copy. better even, avoid the whole situation, allocate your Mat properly, and do not use a double[], but mat.at<double>()

your returned Mat from extract_features_mat() is invalid.

if you construct a Mat with a "borrowed" data pointer, it is just doing a "shallow" copy, only the pointer gets copiied, not the data, so once the original pointer gets goes out of scope (because it is local, and you return from the function), you got a "dangling" pointer.

try :

return Mat(1,feature_size, CV_64FC1, feature_value).clone() ;

to achieve a "deep" copy. better even, avoid the whole situation, allocate your Mat properly, and do not use a double[], but mat.at<double>()

your returned Mat from extract_features_mat() is invalid.

if you construct a Mat with a "borrowed" data pointer, it is just doing a "shallow" copy, only the pointer gets copiied, not the data, so once the original pointer goes out of scope (because it is local, and you return from the function), you got a "dangling" pointer.

try :

return Mat(1,feature_size, CV_64FC1, feature_value).clone() ;

to achieve a "deep" copy. better even, avoid the whole situation, allocate your Mat properly, properly at the beginning of your function, and do not use a seperate double[], but mat.at<double>() double *feature_value = mat.ptr<double>(0);

your returned Mat from extract_features_mat() is invalid.

if you construct a Mat with a "borrowed" data pointer, it is just doing a "shallow" copy, only the pointer gets copiied, not the data, so once the original pointer goes out of scope (because it is local, and you return from the function), you got a "dangling" pointer.

try :

return Mat(1,feature_size, Mat(1, feature_size, CV_64FC1, feature_value).clone() ;

to achieve a "deep" copy.

better even, avoid the whole situation, allocate your Mat properly at the beginning of your function, and do not use it's data, instead of a seperate double[], but double []:

Mat extract_features_mat(Mat descriptor, std::vector<float> hog_ders)
{
        int feature_size = descriptor.cols + hog_ders.size() ;
        Mat result(1, feature_size, CV_64FC1) ; 
        double *feature_value = mat.ptr<double>(0);result.ptr<double>(0);

        //
        // calculate feature_value, like before
        //

        return result;
}