Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:33:01+00:00 2026-06-15T03:33:01+00:00

I am using OpenCV via Matlab to detect faces in a video and then

  • 0

I am using OpenCV via Matlab to detect faces in a video and then do some processing using Matlab. At the moment I do face detection on the IplImage-structured frames (queried by cvQueryFrame) of the video. I save each of the queried frames as a jpg and then use the face coordinates to get the ROI for the required processing. See the portion of code outlining this below.

% 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..

This being the case, I feel that there should be an easier and less-crude way to convert an ‘IplImage’ image to a matrix or array in Matlab. Is this a possibility? If yes,how is this done?

Some pointers in this direction would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:33:03+00:00Added an answer on June 15, 2026 at 3:33 am

    Try mexing the following code:

    /*
     * 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 );
        }
    }
    

    You’ll end up with a function (mex) IplImage2mxArray, use it in Matlab:

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

    Due to internal opencv representations the channels of img might be permuted (BGR instread of RGB). Also note that img might contain four channels – an additional alpha channel.

    -Shai

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Opencv for some real-time video processing. As a front-end I am
I am using OpenCV for some of my image processing related codes. I am
Hi I am using OpenCV face-detection sample(OpenCV 2.4.2). I have changed the face-detection sample
I am using OpenCV's face detection. It works fine when it comes to drawing
I'm using OpenCV to do some processing on an AVI file. Everything is working
I am using OpenCV for face and eye detection. To start with, I tested
I'm using OpenCV for an application in computer vision. I'd like to accelerate some
I've started using opencv to detect features: A sequence like: cv::SurfFeatureDetector detector( 40 );
Hi I am trying to detect web cam in opencv using following code I
I am using opencv to process very large images (some times even more than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.