0

I'm running some very simple code:

library(opencv)
ocv_video(ocv_face)

And the session immediately aborts.

Any ideas? (note: running R 4.0.2)

enter image description here

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] opencv_0.1

loaded via a namespace (and not attached):
[1] compiler_4.0.2 magrittr_1.5   tools_4.0.2    Rcpp_1.0.4.6 
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
stevec
  • 41,291
  • 27
  • 223
  • 311
  • OS, please?.... – Rui Barradas Jul 18 '20 at 17:21
  • @RuiBarradas updated with full info, but: macOS Catalina – stevec Jul 18 '20 at 17:23
  • 2
    Works on Windows 10. I will update the tags. Done. – Rui Barradas Jul 18 '20 at 17:23
  • 1
    Works on Ubuntu 18.04 as well. So seems to be Mac Specific – Julian_Hn Jul 18 '20 at 18:41
  • You have opencv 3+ installed? – Chris Jul 20 '20 at 21:57
  • @Chris I am not sure, I simply ran `install.packages("opencv")` and the code in the question, that's all. Do I do something additional? – stevec Jul 24 '20 at 13:54
  • I am probably leading you wrong, but generally, when I read 'bindings' as in bindings to library, x,y,z, I have the library (from source or header files - I'm ubuntu, so if you can stand the pain, and opencv is a pain, `To install from source on MacOS, you need to install the opencv library from homebrew: brew install opencv` then install.packages..., but as I say, I may be leading you to a painful and unnecessary process, but the seg-fault suggests that some small, working subset of opencv is not provided in the r pkg, merely 'bindings', HTH – Chris Jul 24 '20 at 19:18
  • @Chris I ran `brew install opencv` and it ran for some time (~ 20 min), installing mysql and python 3.8. When it completed I ran `install.packages("opencv")` and the code in the question, with exactly the same result – stevec Jul 25 '20 at 06:43
  • Have you tried doing `install.packages('opencv') in a terminal session of R? – Chris Jul 25 '20 at 11:59
  • @Chris just tried, but still get the same error – stevec Jul 25 '20 at 12:15
  • I'd say it's down to file a bug report. – Chris Jul 25 '20 at 12:40
  • @Chris I just checked out the github repo, and as a final check before submitting a bug report, installed the dev version direct from github. Now after `library(opencv)` it warns: `Warning: Camera might crash rstudio due to Mojave privacy protection`, and after a quick google search, it appears this is a common problem – stevec Jul 25 '20 at 12:51
  • After following this simple idea [here](https://stackoverflow.com/a/56175234/5783745) to run the code from the R interpreter in the terminal, MacOS prompts for access ,and then works from the terminal. Note that I still can't get it working from RStudio (which isn't a problem in my case) – stevec Jul 25 '20 at 12:56

1 Answers1

0

Solution

For anyone else who arrives here, the solution is to run the same code from terminal. That is press cmd + space to bring up spotlight search, type terminal to open terminal. Type R to open the R interpreter, and use that instead of RStudio.

Cause of the crash

The reason it works from terminal but no RStudio is because from terminal, a prompt will appear asking you to give opencv permission to use your webcam, but this prompt will not appear in RStudio (it causes the crash).

stevec
  • 41,291
  • 27
  • 223
  • 311