how to enable multi-thread in CMake (centos) ?
hi,
I've issue with multi thread and CMAKE
I've written this code using multi-thread it works fine in windows, however, when I tried to run it in CentOS using CMAKE it works in a sequential manner which is weird
project structure :
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( main )
find_package( OpenCV REQUIRED )
add_executable( main main.cpp )
target_link_libraries( main ${OpenCV_LIBS} )
code
#include <iostream> // for standard I/O
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
// uncomment this to run it in Centos
//#include "opencv2/imgproc/imgproc_c.h"
//#include <opencv2/highgui/highgui_c.h>
//#include "opencv2/videoio/videoio_c.h"
#include <thread>
#include <future>
using namespace std;
using namespace cv;
int loadVideo( VideoCapture cap1, int seek_step,int thrd){
int frameNum = 0;
Mat frame;
char c;
cap1.set(CV_CAP_PROP_POS_FRAMES, seek_step );
while (1){
cap1 >> frame;
if (frame.empty())
{
cout << " < < < Channel stream ended! > > > ";
break;
}
cout<<"\nseek_step" <<seek_step << "frameNum" << frameNum << endl;
++frameNum;
}
return frameNum;
}
int main()
{
string sourceVideoPath;
sourceVideoPath = "C:\\opencvVid\\case1_320_240\\case320_240fps10.mp4";
// sourceVideoPath = "./media/case320_240fps10.mp4";
VideoCapture cap1(sourceVideoPath);
VideoCapture cap2(sourceVideoPath);
VideoCapture cap3(sourceVideoPath);
cout << "Stream frame numbre : " << cap1.get(CV_CAP_PROP_FRAME_COUNT)<<endl;
if (!cap1.isOpened())
{
cout << "Could not open reference " << sourceVideoPath << endl;
return -1;
}
auto future1 = std::async(loadVideo, cap1,0,1);
auto future2 = std::async(loadVideo, cap2,750,2);
auto future3 = std::async(loadVideo, cap3,1000,3);
cout << future1.get() << endl;
cout << future2.get() << endl;
cout << future3.get() << endl;
return 0;
}
output in windows :
Stream frame numbre : 36206
seek_step0frameNum0
seek_step0frameNum
seek_step1
750frameNum
seek_step0
0
seek_stepframeNum750frameNum2
1
seek_step1000frameNum
seek_step
seek_step750frameNum2
0
0frameNum3
seek_step
seek_step
seek_step01000750frameNum3
frameNum1
frameNum
seek_step7504
seek_step1000frameNum2
frameNum4
seek_step
seek_step
seek_step7501000frameNum3
frameNum5
0
seek_step1000frameNum4
seek_step750frameNum6frameNum5
output in CentOS:
[azdoud@video-processor proj1]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
[azdoud@video-processor proj1]$ make
[azdoud@video-processor proj1]$ ./main
Stream frame numbre : 36206
seek_step0frameNum0
seek_step0frameNum1
seek_step0frameNum2
seek_step0frameNum3
seek_step0frameNum4
seek_step0frameNum5
seek_step0frameNum6
seek_step0frameNum7
seek_step0frameNum8
seek_step0frameNum9
seek_step0frameNum10
seek_step0frameNum11
seek_step0frameNum12
seek_step0frameNum13
seek_step0frameNum14
seek_step0frameNum15
seek_step0frameNum16
seek_step0frameNum17
seek_step0frameNum18
seek_step0frameNum19
seek_step0frameNum20
seek_step0frameNum21
seek_step0frameNum22
seek_step0frameNum23
seek_step0frameNum24
seek_step0frameNum25
seek_step0frameNum26
seek_step0frameNum27
seek_step0frameNum28
seek_step0frameNum29
seek_step0frameNum30
seek_step0frameNum31
seek_step0frameNum32
seek_step0frameNum33
seek_step0frameNum34
seek_step0frameNum35
seek_step0frameNum36
seek_step0frameNum37
seek_step0frameNum38
seek_step0frameNum39
seek_step0frameNum40
seek_step0frameNum41
seek_step0frameNum42
seek_step0frameNum43
seek_step0frameNum44
seek_step0frameNum45
seek_step0frameNum46
seek_step0frameNum47
seek_step0frameNum48
Is there no explanation ?