iOS Video processing is very slow

asked 2014-03-31 21:35:54 -0500

Jvaeyhcd gravatar image

I have read the article about OpenCV iOS - Video Processing In the - (void)processImage:(Mat&)image; function can deal with the video's image and output on the screen.Now I want to sign out the car in the video and let it show on the screen by a react.So i changed the - (void)processImage:(Mat&)image; function:

NSString *path = [[NSBundle mainBundle] pathForResource:@"car" ofType:@"xml"];
const char *pstrImage = [path cStringUsingEncoding:NSASCIIStringEncoding];
pHaarCascade = (CvHaarClassifierCascade*)cvLoad(pstrImage);
IplImage pSrcImage = image;
NSLog(@"%d*%d",image.cols,image.rows);

// IplImage *pSrcImage = cvCreateImage(cvSize(image.cols/2, image.rows/2), image.depth(), image.channels()); IplImage *pGrayImage = cvCreateImage(cvGetSize(&pSrcImage), IPL_DEPTH_8U, 1); cvCvtColor(&pSrcImage, pGrayImage, CV_BGR2GRAY);

if (pHaarCascade != NULL) {
    CvScalar carCircleColors[]=
    {
        {{0,0,255}},
        {{0,128,255}},
        {{0,255,255}},
        {{0,255,0}},
        {{255,128,0}},
        {{255,255,0}},
        {{255,0,0}},
        {{255,0,255}}
    };
    CvMemStorage *pcvMStorage = cvCreateMemStorage(0);
    cvClearMemStorage(pcvMStorage);

    //识别
    CvSeq *pcvSeqFaces = cvHaarDetectObjects(pGrayImage, pHaarCascade, pcvMStorage);
    NSLog(@"车辆个数:%d",pcvSeqFaces->total);
    for(int i = 0; i < pcvSeqFaces->total; i++)
    {
        CvRect* r = (CvRect*)cvGetSeqElem(pcvSeqFaces, i);
        CvPoint p1,p2;
        p1.x = r->x;
        p2.x = r->x + r->width;
        p1.y = r->y;
        p2.y = r->y + r->height;
        cvRect(p1.x, p1.y, p2.x, p2.y);
        cvRectangle(&pSrcImage, p1, p2, carCircleColors[ i % 8]);
    }
    cvReleaseMemStorage(&pcvMStorage);
    image = &pSrcImage;
} else {
    NSLog(@"没有车辆");
}
cvReleaseImage(&pGrayImage);

this function can react out the car on the screen but i found it was very slow,that's let me crazy.I want to know how can i let it work quickly.(I am a Chinese,my English is very poor.)

edit retag flag offensive close merge delete