99# '
1010# ' @examples
1111# ' \dontrun{
12- # ' defaultOpenCVPath()
12+ # ' defaultOpenCVPath()
1313# ' }
1414# '
1515# ' @export
@@ -23,15 +23,16 @@ defaultOpenCVPath <- function() {
2323 config <- list ()
2424
2525 config $ arch <- unname(Sys.info()[" machine" ])
26- if (! grepl(" 64" , config $ arch ))
26+ if (! grepl(" 64" , config $ arch )) {
2727 stop(" Unsupported CPU architecture." )
28+ }
2829
2930 config $ os_type <- .Platform $ OS.type
3031
3132 if (config $ os_type == " windows" ) {
3233 config $ install_path <- utils :: shortPathName(install_path )
3334 config $ pkg_path <- utils :: shortPathName(find.package(" ROpenCVLite" ))
34- config $ os <- gsub(" \r " , " " , gsub(" Caption=" , " " , system(' wmic os get Caption,CSDVersion /value' , intern = TRUE )[3 ]))
35+ config $ os <- gsub(" \r " , " " , gsub(" Caption=" , " " , system(" wmic os get Caption,CSDVersion /value" , intern = TRUE )[3 ]))
3536 config $ core <- paste0(" https://github.com/opencv/opencv/archive/" , version , " .tar.gz" )
3637 config $ contrib <- paste0(" https://github.com/opencv/opencv_contrib/archive/" , version , " .tar.gz" )
3738 rtools <- .findRtools()
@@ -94,34 +95,36 @@ defaultOpenCVPath <- function() {
9495 paste0(
9596 ' "' , config $ cmake_path , ' "' ,
9697 ' -G "Unix Makefiles"' ,
97- ' -Wno-dev' ,
98+ " -Wno-dev" ,
9899 ' -DCMAKE_C_COMPILER="' , config $ gcc_path , ' "' ,
99100 ' -DCMAKE_CXX_COMPILER="' , config $ gpp_path , ' "' ,
100101 switch (config $ os_type ,
101- windows = paste0(' -DCMAKE_RC_COMPILER="' , config $ windres_path , ' "' ,
102- ' -DOpenCV_ARCH=x64' ,
103- ' -DOpenCV_RUNTIME=mingw' ,
104- ' -DBUILD_SHARED_LIBS=ON' ,
105- ' -DCPU_DISPATCH=SSE4_1,SSE4_2,FP16,AV' )
102+ windows = paste0(
103+ ' -DCMAKE_RC_COMPILER="' , config $ windres_path , ' "' ,
104+ " -DOpenCV_ARCH=x64" ,
105+ " -DOpenCV_RUNTIME=mingw" ,
106+ " -DBUILD_SHARED_LIBS=ON" ,
107+ " -DCPU_DISPATCH=SSE4_1,SSE4_2,FP16,AV"
108+ )
106109 ),
107110 ' -DCMAKE_MAKE_PROGRAM="' , config $ make_path , ' "' ,
108- ' -DCMAKE_CXX_STANDARD=11' ,
109- ' -DENABLE_PRECOMPILED_HEADERS=OFF' ,
110- ' -DOPENCV_EXTRA_MODULES_PATH=' , config $ contrib_dir ,
111- ' -DBUILD_LIST=calib3d,core,dnn,features2d,flann,gapi,highgui,imgcodecs,imgproc,ml,objdetect,photo,stitching,video,videoio,ximgproc,wechat_qrcode' ,
112- ' -DOPENCV_GENERATE_PKGCONFIG=ON' ,
113- ' -DWITH_OPENMP=ON' ,
114- ' -DWITH_TBB=ON' ,
115- ' -DWITH_EIGEN=ON' ,
116- ' -DWITH_LAPACK=ON' ,
117- ' -DBUILD_opencv_world=OFF' ,
118- ' -DBUILD_opencv_contrib_world=OFF' ,
119- ' -DBUILD_PERF_TESTS=OFF' ,
120- ' -DBUILD_TESTS=OFF' ,
111+ " -DCMAKE_CXX_STANDARD=11" ,
112+ " -DENABLE_PRECOMPILED_HEADERS=OFF" ,
113+ " -DOPENCV_EXTRA_MODULES_PATH=" , config $ contrib_dir ,
114+ " -DBUILD_LIST=calib3d,core,dnn,features2d,flann,gapi,highgui,imgcodecs,imgproc,ml,objdetect,photo,stitching,video,videoio,ximgproc,wechat_qrcode" ,
115+ " -DOPENCV_GENERATE_PKGCONFIG=ON" ,
116+ " -DWITH_OPENMP=ON" ,
117+ " -DWITH_TBB=ON" ,
118+ " -DWITH_EIGEN=ON" ,
119+ " -DWITH_LAPACK=ON" ,
120+ " -DBUILD_opencv_world=OFF" ,
121+ " -DBUILD_opencv_contrib_world=OFF" ,
122+ " -DBUILD_PERF_TESTS=OFF" ,
123+ " -DBUILD_TESTS=OFF" ,
121124 ' -DCMAKE_C_FLAGS_RELEASE="-fstack-protector-strong"' ,
122125 ' -DCMAKE_CXX_FLAGS_RELEASE="-fstack-protector-strong"' ,
123- ' -DINSTALL_CREATE_DISTRIB=ON' ,
124- ' -DCMAKE_BUILD_TYPE=RELEASE' ,
126+ " -DINSTALL_CREATE_DISTRIB=ON" ,
127+ " -DCMAKE_BUILD_TYPE=RELEASE" ,
125128 ' -DCMAKE_INSTALL_PREFIX="' , config $ install_path , ' "' ,
126129 ' -B"' , config $ build_dir , ' "' ,
127130 ' -H"' , config $ source_dir , ' "'
@@ -149,15 +152,13 @@ defaultOpenCVPath <- function() {
149152# '
150153# ' @examples
151154# ' \dontrun{
152- # ' installOpenCV()
155+ # ' installOpenCV()
153156# ' }
154157# '
155158# ' @export
156159installOpenCV <- function (install_path = defaultOpenCVPath(), batch = FALSE ) {
157160 install <- 0
158- pkg_version <- paste0(
159- strsplit(as.character(utils :: packageVersion(" ROpenCVLite" )), " " )[[1 ]][c(1 , 3 , 4 )],
160- collapse = " ." )
161+ pkg_version <- " 4.11.0"
161162
162163 if (interactive()) {
163164 if (isOpenCVInstalled()) {
@@ -166,16 +167,19 @@ installOpenCV <- function(install_path = defaultOpenCVPath(), batch = FALSE) {
166167 if (pkg_version == cv_version ) {
167168 install <- utils :: menu(
168169 c(" yes" , " no" ),
169- title = " OpenCV is already installed on this system. Would you like to reinstall it now? This will take several minutes." )
170+ title = " OpenCV is already installed on this system. Would you like to reinstall it now? This will take several minutes."
171+ )
170172 } else {
171173 install <- utils :: menu(
172174 c(" yes" , " no" ),
173- title = " A new version of OpenCV is available. Would you like to install it now? This will take several minutes." )
175+ title = " A new version of OpenCV is available. Would you like to install it now? This will take several minutes."
176+ )
174177 }
175178 } else {
176179 install <- utils :: menu(
177180 c(" yes" , " no" ),
178- title = " OpenCV is not installed on this system. Would you like to install it now? This will take several minutes." )
181+ title = " OpenCV is not installed on this system. Would you like to install it now? This will take several minutes."
182+ )
179183 }
180184 } else {
181185 if (batch ) {
@@ -186,8 +190,9 @@ installOpenCV <- function(install_path = defaultOpenCVPath(), batch = FALSE) {
186190 }
187191 }
188192
189- if (! isCmakeInstalled())
193+ if (! isCmakeInstalled()) {
190194 install <- 0
195+ }
191196
192197 if (install == 1 ) {
193198 config <- .configure(normalizePath(install_path , mustWork = FALSE ), pkg_version )
@@ -225,15 +230,26 @@ installOpenCV <- function(install_path = defaultOpenCVPath(), batch = FALSE) {
225230 insert <- c(
226231 ' # set CMAKE_INSTALL_NAME_DIR if CMAKE_INSTALL_PREFIX isn\' t default value of "/usr/local"' ,
227232 ' if(UNIX AND NOT ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local")' ,
228- ' set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)' ,
233+ " set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)" ,
229234 ' # message ("setting CMAKE_INSTALL_NAME_DIR: ${CMAKE_INSTALL_NAME_DIR}")' ,
230- ' endif()' ,
231- ' '
235+ " endif()" ,
236+ " "
237+ )
238+ writeLines(
239+ c(tmp [1 : ix ], insert , tmp [(ix + 1 ): length(tmp )]),
240+ paste0(config $ source_dir , " cmake/OpenCVModule.cmake" )
232241 )
233- writeLines(c(tmp [1 : ix ], insert , tmp [(ix + 1 ): length(tmp )]),
234- paste0(config $ source_dir , " cmake/OpenCVModule.cmake" ))
235242 }
236243
244+ # To be removed once the CMake 4 issue is resolved in the next OpenCV release
245+ tmp <- readLines(paste0(config $ source_dir , " cmake/OpenCVGenPkgconfig.cmake" ))
246+ ix <- which(grepl(" cmake_minimum_required" , tmp ))
247+ insert <- " cmake_minimum_required(VERSION 3.5)"
248+ writeLines(
249+ c(tmp [1 : (ix - 1 )], insert , tmp [(ix + 1 ): length(tmp )]),
250+ paste0(config $ source_dir , " cmake/OpenCVGenPkgconfig.cmake" )
251+ )
252+
237253 dir.create(config $ build_dir , showWarnings = FALSE )
238254 system(.cmake(config ))
239255 system(paste0(config $ make_path , " -j" , parallel :: detectCores(), " -C " , config $ build_dir ))
@@ -257,15 +273,16 @@ installOpenCV <- function(install_path = defaultOpenCVPath(), batch = FALSE) {
257273# '
258274# ' @examples
259275# ' \dontrun{
260- # ' installOpenCV()
276+ # ' installOpenCV()
261277# ' }
262278# '
263279# ' @export
264280removeOpenCV <- function () {
265281 if (isOpenCVInstalled()) {
266282 uninstall <- utils :: menu(
267283 c(" yes" , " no" ),
268- title = " Would you like to completely remove OpenCV from your R installation? You can reinstall it at any time by using the installOpenCV() function." )
284+ title = " Would you like to completely remove OpenCV from your R installation? You can reinstall it at any time by using the installOpenCV() function."
285+ )
269286 print(uninstall )
270287
271288 if (uninstall == 1 ) {
0 commit comments