ShiqiYu / libfacedetection

An open source library for face detection in images. The face detection speed can reach 1000FPS.
Other
12.27k stars 3.05k forks source link

Usage in a multithreaded context #77

Closed nicholasc closed 5 years ago

nicholasc commented 5 years ago

The facedetect_cnn function does not seem to be thread-safe. I get an access violation error when I try to use it across different threads.

I'm comfortable in using it in a thread safe manner but how is that going to improve the performance? I was wondering if you could explain how you obtained your single-threaded vs multi-threaded results published in the readme.

ShiqiYu commented 5 years ago

Thank you for the information. I will test it later. If possible, could you post your code segmentation?

On Tue, Jan 29, 2019 at 5:58 AM Nicholas Charbonneau < notifications@github.com> wrote:

The facedetect_cnn function does not seem to be thread-safe. I get an access violation error when I try to use it across different threads.

I'm comfortable in using it in a thread safe manner but how is that going to improve the performance? I was wondering if you could explain how you obtained your single-threaded vs multi-threaded results published in the readme.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ShiqiYu/libfacedetection/issues/77, or mute the thread https://github.com/notifications/unsubscribe-auth/AG0eHcmfpCvxUMGL1FAHatlCrwxeESrYks5vH3KQgaJpZM4aW3FO .

deimsdeutsch commented 5 years ago

@nicholasc You are better off using FaceBoxes or some other library. libFaceDetection does not have the accuracy to work in real world environment.

1997huoda commented 5 years ago
``void process_image(Mat mat)
{
    int * pResults = NULL; 
    //pBuffer is used in the detection functions.
    //If you call functions in multiple threads, please create one buffer for each thread!
    unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
    if(!pBuffer)
    {
        fprintf(stderr, "Can not alloc buffer.\n");
        return ;
    }

    //!!! The input image must be a RGB one (three-channel)
    //!!! DO NOT RELEASE pResults !!!
    float t = getticks();
    pResults = facedetect_cnn(pBuffer, (unsigned char*)(mat.ptr(0)), mat.cols, mat.rows, (int)mat.step);
    t = getticks() - t;
    if(t!=0)    cout<<"     time     "<<t*1000<<"ms"<<endl;
    printf("%d faces detected.\n", (pResults ? *pResults : 0));

    //print the detection results
    for(int i = 0; i < (pResults ? *pResults : 0); i++)
    {
        short * p = ((short*)(pResults+1))+142*i;
        int x = p[0];
        int y = p[1];
        int w = p[2];
        int h = p[3];
        int neighbors = p[4];
        int angle = p[5];
        location good={x,y,w,h};
        final_location.push_back(good);
        printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x,y,w,h,neighbors, angle);
//      rectangle(mat, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
    }       
}
double free or corruption (!prev)
已放弃 (核心已转储)
1997huoda commented 5 years ago

多线程访问

1997huoda commented 5 years ago

线程不安全 不能多线程同时使用detection ,异步线程可以访问 但是也不稳定