Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Matlab中Iplimage到矩阵或数组的转换_Arrays_Matlab_Opencv_Matrix_Iplimage - Fatal编程技术网

Arrays Matlab中Iplimage到矩阵或数组的转换

Arrays Matlab中Iplimage到矩阵或数组的转换,arrays,matlab,opencv,matrix,iplimage,Arrays,Matlab,Opencv,Matrix,Iplimage,我通过Matlab使用OpenCV检测视频中的人脸,然后使用Matlab进行一些处理。目前,我在视频的IplImage结构化帧(由cvQueryFrame查询)上进行人脸检测。我将每个查询到的帧保存为jpg,然后使用面部坐标获得所需处理的ROI。请参阅下面概述这一点的代码部分 % After reading in frame from video.. for i=1:size img = calllib('highgui210','cvQueryFrame',cvCapture);

我通过Matlab使用OpenCV检测视频中的人脸,然后使用Matlab进行一些处理。目前,我在视频的IplImage结构化帧(由cvQueryFrame查询)上进行人脸检测。我将每个查询到的帧保存为jpg,然后使用面部坐标获得所需处理的ROI。请参阅下面概述这一点的代码部分

% After reading in frame from video..
for i=1:size
    img = calllib('highgui210','cvQueryFrame',cvCapture);
    calllib('cxcore210','cvFlip',img,img,1);
    calllib('highgui210', 'cvSaveImage', 'ThisFrame.jpg', img, ptr); 
% Rest of the processing comes here..
在这种情况下,我觉得应该有一种更简单、更简单的方法来将“IplImage”图像转换为Matlab中的矩阵或数组。这有可能吗?如果是,这是如何做到的


在此方向上的一些指针将不胜感激

尝试混合以下代码:

/*
 * Usage:
 *   img = IplImage2mxArray( cvImgPtr, releaseFlag );
 */
void mexFunction( int nout, mxArray* pout[], int nin, const mxArray* pin[]) {
    if ( nin != 2 )
        mexErrMsgTxt("wrong number of inputs");
    if ( nout != 1 )
        mexErrMsgTxt("wrong number of outputs");
    IplImage* cvImg = (IplImage*)mxGetData(pin[0]); // get the pointer
    // allocate the output
    mwSize imgDims[3] = {cvImg->height,  cvImg->width, cvImg->nChannels};
    pout[0] = mxCreateNumericArray( 3, imgDims, mxDOUBLE_CLASS, mxREAL );
    if ( pout[0] == NULL )
        mexErrMsgTxt("out of memeory");
    double* imgP = mxGetPr(pout[0]);
    double divVal = pow(2.0, cvImg->depth) - 1;
    double releaseFlag = mxGetScalar( pin[1] );
    for ( int x = 0 ; x < cvImg->width; x++ ) {
        for ( int y = 0 ; y < cvImg->height; y++ ) {
            CvScalar s = cvGet2D(cvImg, y, x);
            for (int c = 0; c < cvImg->nChannels; c++) {
                imgP[ y + x * cvImg->height + c * cvImg->height * cvImg->width ] = s.val[c] / divVal;
            }
        }
    }
    if ( releaseFlag != 0 ) {
        cvReleaseImage( &cvImg );
    }
}
由于内部opencv表示,img的通道可能会被置换(RGB的BGR instread)。还请注意,img可能包含四个通道-一个额外的alpha通道

-谢

>> cvImg = calllib('highgui210','cvQueryFrame',cvCapture);
>> img = IplImage2mxArray( cvImg, false ); % no cvReleaseImage after cvQueryFrame