由于我使用的是 C++,所以已经有了 std::thread 类。
所以我的简单任务可以通过这段代码完成:
void detAndComputeT(detectorData &data) {
Ptr<SIFT> detector = cv::SIFT::create();
detector->detectAndCompute(data.image, Mat(), data.keypoints, data.descriptors);
}
和
std::thread threads2[2];
detectorData dataImage1;
detectorData dataImage2;
dataImage1.image = image1_toCalc;
dataImage2.image = image2_toCalc;
threads2[0] = thread(detAndComputeT, std::ref(dataImage1));
threads2[1] = thread(detAndComputeT, std::ref(dataImage2));
threads2[0].join();
threads2[1].join();