从'size_t'转换为'int' [英] conversion from 'size_t' to 'int'

查看:531
本文介绍了从'size_t'转换为'int'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matlab 2013a x64和win7 x64。安装opencv路径(c:\ openncv.2.4.7.2)



你是如何编译me_HaarDetectOpenCV.cpp的?



matlab命令窗口:

i'm using matlab 2013a x64 and win7 x64 . install the opencv path (c:\opencv.2.4.7.2)

How did you compile me_HaarDetectOpenCV.cpp ?

matlab command window:

>> mex -LC:\opencv\build\x64\vc11\lib -IC:\opencv\build\include\opencv -lcv -lcxcore me_HaarDetectOpenCV.cpp
me_HaarDetectOpenCV.cpp 
me_HaarDetectOpenCV.cpp(29) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data 
me_HaarDetectOpenCV.cpp(48) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data 
me_HaarDetectOpenCV.cpp(49) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data 
me_HaarDetectOpenCV.cpp(64) : error C3861: 'round': identifier not found 
me_HaarDetectOpenCV.cpp(66) : error C3861: 'round': identifier not found 
me_HaarDetectOpenCV.cpp(70) : error C3861: 'round': identifier not found 

  D:\PROGRA~2\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'me_HaarDetectOpenCV.cpp' failed. 

Error using mex (line 206)
Unable to complete successfully.







代码(me_HaarDetectOpenCV.cpp):




code(me_HaarDetectOpenCV.cpp ):

#include "mex.h"
#include "cv.h"
#include "highgui.h"

// compiled with opencv2.0 gives different results then opencv2.1
// e.g. buffy_s5e2/buffy_s5e2_frames/001668.jpg

// matlab interface to OpenCV cvHaarDetectObjects function
// author: Marcin Eichner


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    char *classifiername;
    int classifiername_length,ncols, nrows,c,r,d;
    uchar *image_pointer; // equivalent to uint8
    uchar temp;
    const int flags = 0; // no CV_HAAR_DO_CANNY_PRUNING
    // init default values:
    double scale_factor = 1.1;
    int min_neighbors = 2,min_size_x = 30,min_size_y = 30;

    if(nrhs < 2 || nrhs > 7)
      mexErrMsgTxt("ERROR: 2-7 arguments expected: <string xml model path>, <uint8 grayscale image>,\n"
              "[min_size_x], [min_size_y], [scale_factor], [min_neighbors]\n"
              "for optional arguments 3-7 check the cvHaarDetectObjects opencv function help");
    if (!mxIsChar(prhs[0]))
      mexErrMsgTxt("arg1 must be a string - absolute/relative path to the classifier");
    classifiername_length = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
    classifiername = mxArrayToString(prhs[0]);

    // HANDLE INPUT

    // read in the classifier
    CvHaarClassifierCascade * cascade = (CvHaarClassifierCascade*) cvLoad( classifiername, 0, 0, 0);
    if(!cascade)
       mexErrMsgTxt("ERROR: Could not load the classifier" );

    /* Check if the prhs image is in double format*/
    if (!(mxIsUint8(prhs[1])))
      mexErrMsgTxt("ERROR: arg2 (image) must be of type uint8");

    int image_ndim = mxGetNumberOfDimensions(prhs[1]);
    if (mxGetNumberOfDimensions(prhs[1]) > 2)
      mexErrMsgTxt("ERROR: arg2 (image) must be a imgscale image");

    image_pointer =  (uchar*)mxGetPr(prhs[1]);
    ncols = mxGetN(prhs[1]);
    nrows = mxGetM(prhs[1]);

    IplImage* img = cvCreateImage( cvSize(ncols, nrows), IPL_DEPTH_8U, 1 );

    // Load the column wise vector into the IplImage
    // IplImage data is read in a rowwise manner
    // Appropriate conversion is carried out here
    for(c=0;c<ncols;c++)
       for(r=0;r<nrows;r++)
        {
            temp = (uchar)image_pointer[r+(nrows*c)];
            ((uchar *)(img->imageData + r*img->widthStep))[c]=temp;
        }

    if (nrhs > 2)
      min_size_x = (int)round(mxGetScalar(prhs[2]));
    if (nrhs > 3)
      min_size_y = (int)round(mxGetScalar(prhs[3]));
    if (nrhs > 4)
      scale_factor = mxGetScalar(prhs[4]);
    if (nrhs > 5)
      min_neighbors = (int)round(mxGetScalar(prhs[5]));

    CvMemStorage* storage = cvCreateMemStorage(0);

    // PROCESS IMAGE

    // equalize hist image before running face detection;
    cvEqualizeHist(img, img);

    //mexPrintf("%f %d %d %d %d",scale_factor,min_neighbors,flags,min_size_x,min_size_y);
    // run the classifier
    CvSeq* detections = cvHaarDetectObjects(img, cascade, storage, scale_factor, min_neighbors, flags,
                                            cvSize(min_size_x, min_size_y));

    if (detections->total == 0)
    {
      plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL);
      cvReleaseImage(&img);
      cvReleaseHaarClassifierCascade(&cascade);
      cvReleaseMemStorage(&storage);
      return;
    }
    else
    {
        plhs[0] = mxCreateDoubleMatrix(detections->total, 4, mxREAL);
        double* output = mxGetPr(plhs[0]);
        CvRect* rect;
        for(d = 0; d < detections->total; d++)
        {
           rect = (CvRect*)cvGetSeqElem(detections, d);
           output[d] = rect->x+1;
           output[d+detections->total*1] = rect->y+1;
           output[d+detections->total*2] = rect->width;
           output[d+detections->total*3] = rect->height;
        }
    }
    cvReleaseImage(&img);
    cvReleaseHaarClassifierCascade(&cascade);
    cvReleaseMemStorage(&storage);
//     cvDestroyAllWindows();
}

推荐答案

鉴于有关此主题的问题数量,您可能希望花一些时间了解为何会出现这些错误消息。我假设第一个警告发生在该行:

Given the number of questions on this subject, you may like to spend some time learning why these error messages occur. I am assuming that the first warning occurs on the line:
classifiername_length = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;



所以我也必须假设这些 mxGetX 函数返回的值为 size_t (即 unsigned int )类型。您已将 classifiername_length 声明为 int 类型,并且编译器只是警告您它不能将值保持为大作为最大的 size_t 所以你可能需要修改你的代码。



三条错误信息只是告诉你您在代码中调用名为 round 的函数,但编译器无法找到它的定义。您必须自己提供,或者包含定义它的头文件。


So I also have to assume that these mxGetX functions return values as size_t (that is unsigned int) types. You have declared classifiername_length as an int type, and the compiler is just warning you that it cannot hold a value as large as the largest size_t so you may need to modifiy your code.

The three error messages are merely telling you that you are calling a function named round in your code, but the compiler cannot find a definition for it. You must either provide it yourself, or include the header file that defines it.


这篇关于从'size_t'转换为'int'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆