I was playing with tesseract and magick ...
library(magick); #install.packages("magick", dependencies=TRUE);
library(tesseract); # install.packages("tesseract");
# https://github.com/ropensci/magick/issues/154
img.file = "iris-ocr.png";
img = magick::image_read( img.file );
img.txt = tesseract::image_ocr(img);
cat(img.txt);
Note: the img.file
was in the same location as the notebook running the code. That is, setwd() was not used, nor a full file path. Yet it worked. To try, here is the PNG image file:
https://raw.githubusercontent.com/MonteShaffer/MasterClassDataAnalytics/main/-course-/02.020_hello-world-notebook/iris-ocr.png
So I dug into the source code of magick
rdx = readRDS("C:\\Users\\Monte J. Shaffer\\Documents\\R\\win-library\\4.1\\magick\\R\\magick.rdx");
info = rdx$variables$magick_image_readpath;
# # https://stackoverflow.com/questions/61841221/how-to-view-open-and-save-a-rdb-file-in-rstudio
readRDB <- function(filename, offset, size, type = 'gzip') {
f <- file(filename, 'rb')
on.exit(close(f))
seek(f, offset + 4)
unserialize(memDecompress(readBin(f, 'raw', size - 4), type))
}
obj = readRDB("C:\\Users\\Monte J. Shaffer\\Documents\\R\\win-library\\4.1\\magick\\R\\magick.rdb", offset=info[1], size=info[2]);
which shows the following:
function (paths, density, depth, strip, defines)
{
.Call("_magick_magick_image_readpath", PACKAGE = "magick",
paths, density, depth, strip, defines)
}
The source Rcpp code shows:
// magick_image_readpath
XPtrImage magick_image_readpath(Rcpp::CharacterVector paths, Rcpp::CharacterVector density, Rcpp::IntegerVector depth, bool strip, Rcpp::CharacterVector defines);
RcppExport SEXP _magick_magick_image_readpath(SEXP pathsSEXP, SEXP densitySEXP, SEXP depthSEXP, SEXP stripSEXP, SEXP definesSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type paths(pathsSEXP);
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type density(densitySEXP);
Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type depth(depthSEXP);
Rcpp::traits::input_parameter< bool >::type strip(stripSEXP);
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type defines(definesSEXP);
rcpp_result_gen = Rcpp::wrap(magick_image_readpath(paths, density, depth, strip, defines));
return rcpp_result_gen;
END_RCPP
}
I am familiar with the __FILE__
syntax of C++ (and PHP):
https://www.tutorialspoint.com/what-are-file-line-and-function-in-cplusplus
Using R and Rcpp, how can I write a macro or function for __FILE__
?
e.g.,
getFILE = function() { __FILE__; }
something similar to:
Rcpp::cppFunction("long long RShift(long long a, int b) { return a >> b;}");
Rcpp::cppFunction("long long LShift(long long a, int b) { return a << b;}");
The follow-up question would be, how to ENABLE those functions when the package installs?