iOS video Processing is slow,how can i run it in background?

asked 2014-03-31 21:40:38 -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;
IplImage *pGrayImage = cvCreateImage(cvGetSize(&pSrcImage), IPL_DEPTH_8U, 1);
cvCvtColor(&pSrcImage, pGrayImage, CV_BGR2GRAY);

if (pHaarCascade != NULL) {
    CvScalar carCircleColors[]=
    CvMemStorage *pcvMStorage = cvCreateMemStorage(0);

    CvSeq *pcvSeqFaces = cvHaarDetectObjects(pGrayImage, pHaarCascade, pcvMStorage);
    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]);
    image = &pSrcImage;
} else {

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


In my experience, using Haarcascade is slow. maybe you could try another algorithm. and see any differences.

gunslinger_ gravatar imagegunslinger_ ( 2014-04-01 04:10:11 -0500 )edit