Skip to content

Commit c93eaad

Browse files
committed
add ocv funcs
1 parent abc1e3c commit c93eaad

17 files changed

+31
-51
lines changed

cmake/opencv.cmake

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Build googletest components
1+
# Build OpenCV components
22
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv/include)
3-
43
include(ExternalProject)
54
ExternalProject_Add(ppc_opencv
65
SOURCE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/opencv"
@@ -11,6 +10,6 @@ ExternalProject_Add(ppc_opencv
1110
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -D CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
1211
-D CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_CXX_FLAGS="-w" -DCMAKE_C_FLAGS="-w" -DENABLE_CCACHE=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF
1312
-DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DWITH_CUDA=OFF -DWITH_OPENCL=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_objdetect=OFF
14-
-DBUILD_opencv_video=OFF -DBUILD_opencv_world=OFF
13+
-DBUILD_opencv_video=OFF -DBUILD_opencv_world=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_flann=OFF -DBUILD_opencv_photo=OFF
1514
BUILD_COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_opencv/build" --config ${CMAKE_BUILD_TYPE} --parallel
1615
INSTALL_COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_CURRENT_BINARY_DIR}/ppc_opencv/build" --prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_opencv/install")

tasks/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ foreach(TASK_TYPE ${LIST_OF_TASKS})
138138
endif ()
139139

140140
add_dependencies(${EXEC_FUNC} ppc_opencv)
141+
target_include_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/install/include/opencv4")
141142
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/install/lib")
143+
if(NOT MSVC)
144+
target_link_libraries(${EXEC_FUNC} PUBLIC
145+
opencv_core opencv_highgui opencv_imgcodecs opencv_imgproc opencv_videoio)
146+
endif()
142147

143148
add_dependencies(${EXEC_FUNC} ppc_googletest)
144149
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")

tasks/all/example/data/pic_mpi.jpg

14.4 KB
Loading

tasks/all/example/data/pic_omp.jpg

20.1 KB
Loading

tasks/all/example/data/pic_seq.jpg

15 KB
Loading

tasks/all/example/data/pic_stl.jpg

50.4 KB
Loading

tasks/all/example/data/pic_tbb.jpg

13.9 KB
Loading

tasks/all/example/data/test_mpi.txt

-1
This file was deleted.

tasks/all/example/data/test_omp.txt

-1
This file was deleted.

tasks/all/example/data/test_seq.txt

-1
This file was deleted.

tasks/all/example/data/test_stl.txt

-1
This file was deleted.

tasks/all/example/data/test_tbb.txt

-1
This file was deleted.

tasks/all/example/func_tests/func_mpi.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <gtest/gtest.h>
22

33
#include <boost/mpi/communicator.hpp>
4-
#include <boost/mpi/environment.hpp>
5-
#include <fstream>
4+
#include <opencv2/opencv.hpp>
65
#include <random>
76
#include <vector>
87

@@ -248,14 +247,10 @@ TEST(Parallel_Operations_MPI, Test_Max_2_File) {
248247
auto task_data_par = std::make_shared<ppc::core::TaskData>();
249248

250249
if (world.rank() == 0) {
251-
std::string line;
252-
std::ifstream test_file(ppc::core::GetAbsolutePath("all/example/data/test_mpi.txt"));
253-
if (test_file.is_open()) {
254-
getline(test_file, line);
255-
}
256-
test_file.close();
257-
258-
const int count_size_vector = std::stoi(line);
250+
cv::Mat img = cv::imread(ppc::core::GetAbsolutePath("all/example/data/pic_mpi.jpg"));
251+
EXPECT_EQ(img.rows, img.cols);
252+
const int count_size_vector = img.rows + img.cols;
253+
259254
global_vec = GetRandomVector(count_size_vector);
260255
task_data_par->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
261256
task_data_par->inputs_count.emplace_back(global_vec.size());

tasks/all/example/func_tests/func_omp.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include <fstream>
3+
#include <opencv2/opencv.hpp>
44
#include <random>
55
#include <vector>
66

@@ -210,14 +210,11 @@ TEST(Parallel_Operations_OpenMP, Test_Mult_2) {
210210
}
211211

212212
TEST(Parallel_Operations_OpenMP, Test_Mult_2_File) {
213-
std::string line;
214-
std::ifstream test_file(ppc::core::GetAbsolutePath("all/example/data/test_omp.txt"));
215-
if (test_file.is_open()) {
216-
getline(test_file, line);
217-
}
218-
test_file.close();
213+
cv::Mat img = cv::imread(ppc::core::GetAbsolutePath("all/example/data/pic_omp.jpg"));
214+
EXPECT_EQ(static_cast<int>(sqrt(img.rows) * sqrt(img.rows)), img.cols);
215+
const int count_size_vector = img.rows + img.cols;
216+
std::vector<int> vec = GetRandomVector(count_size_vector);
219217

220-
std::vector<int> vec = GetRandomVector(std::stoi(line));
221218
// Create data
222219
std::vector<int> ref_res(1, 0);
223220

tasks/all/example/func_tests/func_seq.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include <fstream>
3+
#include <opencv2/opencv.hpp>
44
#include <vector>
55

66
#include "seq/example/include/ops_seq.hpp"
@@ -121,14 +121,9 @@ TEST(Sequential, Test_Sum_100) {
121121
}
122122

123123
TEST(Sequential, Test_Sum_100_From_File) {
124-
std::string line;
125-
std::ifstream test_file(ppc::core::GetAbsolutePath("all/example/data/test_seq.txt"));
126-
if (test_file.is_open()) {
127-
getline(test_file, line);
128-
}
129-
test_file.close();
130-
131-
const int count = std::stoi(line);
124+
cv::Mat img = cv::imread(ppc::core::GetAbsolutePath("all/example/data/pic_seq.jpg"));
125+
EXPECT_EQ(img.rows, img.cols);
126+
const int count = img.rows + img.cols;
132127

133128
// Create data
134129
std::vector<int> in(1, count);

tasks/all/example/func_tests/func_stl.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include <fstream>
3+
#include <opencv2/opencv.hpp>
44
#include <random>
55
#include <thread>
66
#include <vector>
@@ -215,14 +215,11 @@ TEST(Parallel_Operations_STL_Threads, Test_Diff_2) {
215215
}
216216

217217
TEST(Parallel_Operations_STL_Threads, Test_Diff_2_File) {
218-
std::string line;
219-
std::ifstream test_file(ppc::core::GetAbsolutePath("all/example/data/test_stl.txt"));
220-
if (test_file.is_open()) {
221-
getline(test_file, line);
222-
}
223-
test_file.close();
218+
cv::Mat img = cv::imread(ppc::core::GetAbsolutePath("all/example/data/pic_stl.jpg"));
219+
EXPECT_EQ(static_cast<int>(sqrt(img.cols / 2) * sqrt(img.cols / 2)), img.rows);
220+
const int count_size_vector = static_cast<int>(sqrt(sqrt(img.rows)));
224221

225-
auto nthreads = std::thread::hardware_concurrency() * std::stoi(line);
222+
auto nthreads = std::thread::hardware_concurrency() * count_size_vector;
226223
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
227224
// Create data
228225
std::vector<int> ref_res(1, 0);

tasks/all/example/func_tests/func_tbb.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include <fstream>
3+
#include <opencv2/opencv.hpp>
44
#include <random>
55
#include <vector>
66

@@ -209,14 +209,11 @@ TEST(Parallel_Operations_TBB, Test_Mult_2) {
209209
}
210210

211211
TEST(Parallel_Operations_TBB, Test_Mult_2_File) {
212-
std::string line;
213-
std::ifstream test_file(ppc::core::GetAbsolutePath("all/example/data/test_tbb.txt"));
214-
if (test_file.is_open()) {
215-
getline(test_file, line);
216-
}
217-
test_file.close();
212+
cv::Mat img = cv::imread(ppc::core::GetAbsolutePath("all/example/data/pic_tbb.jpg"));
213+
EXPECT_EQ(static_cast<int>(sqrt(img.rows / 2) * sqrt(img.rows / 2)), img.cols);
214+
const int count_size_vector = img.rows + img.cols;
218215

219-
std::vector<int> vec = GetRandomVector(std::stoi(line));
216+
std::vector<int> vec = GetRandomVector(count_size_vector);
220217
// Create data
221218
std::vector<int> ref_res(1, 0);
222219

0 commit comments

Comments
 (0)