Important: Please read the Qt Code of Conduct -

is it possible to use QtConcurrent::mapped inside a QThread ?

  • Hi,

    I want to process my my opencv captured frames in 4 threads.

    one producer (opencv capture ) is very fast

    four worker (detection cpu based) slower than producer (4 times almost)

    I created producer thread and moved a thread.

    1 - Can I create a QtConcurred::mapped in this producer Thread ?

    what is the best practices for this multithreaded video processing in Qt ?

  • Lifetime Qt Champion


    AFAIK, yes you can.

    You have to benchmark the processings you need before designing a pipeline for your video application.

  • @SGaist

    I have below error:

    struct frames_facePhotos
            cv::Mat frames;
            cv::Mat face_photo;
    QVector<frames_facePhotos> framesVector;
               frames_facePhotos process_request;
                process_request.face_photo = face_photo;
                process_request.frames = image;
                framesVector.push_back (process_request);
                process_request.frames = image;
                framesVector.push_back (process_request);
                auto res  = QtConcurrent::mapped(framesVector , &detecFaceModifyFrames );
    void FaceDetector::detecFaceModifyFrames(frames_facePhotos frames_faces)
        int frame_count = 111;
            QString find_face = bc_face->findFace(frames_faces.frames, frames_faces.face_photo,frame_count);
    //    return frames_faces;
    1. Error
      ../BC_DETECTOR/face_detector.cpp:165:60: error: must explicitly qualify name of member function when taking its address
      auto res = QtConcurrent::mapped(framesVector , &detecFaceModifyFrames );

    2nd Error
    /Users/xx/Qt5.12.1/5.12.1/clang_64/lib/QtConcurrent.framework/Headers/qtconcurrentmapkernel.h:175:19: error: no matching function for call to object of type 'QtConcurrent::MemberFunctionWrapper1<void, FaceDetector, FaceDetector::frames_facePhotos>'
    *result = map(*it);

    when I change to :

                auto res  = QtConcurrent::mapped(framesVector , &FaceDetector::detecFaceModifyFrames );

    first error gone but second is there.

  • Lifetime Qt Champion

    @RahibeMeryem Try to use lambda instead of detecFaceModifyFrames. detecFaceModifyFrames is a non static method and cannot be used without class instance.

  • @jsulm

    when I think that I started to capture C++ something like this happening. as a being decent java girl its make me crazy :)

    how can I write its as a lamba ?

  • Lifetime Qt Champion


    auto res  = QtConcurrent::mapped(framesVector , [this](frames_facePhotos frames_faces) {

Log in to reply