- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经通过 reticulate
使用一些 python 功能创建了一个函数包,特别是使用 PIL
打开图像:
image <- "~/Desktop/image.jpg"
pil.image <- reticulate::import( "PIL.Image", convert = FALSE )
img <- pil.image$open( image )
outputs
是我需要的裁剪数据框,所以
crop.grid
只是一个包含 4 个数字的向量。
crop.grid <- c( outputs$x.start[x],
outputs$y.start[x],
outputs$x.stop[x],
outputs$y.stop[x] )
crop.grid <- as.integer( crop.grid )
crop.grid <- reticulate::r_to_py( crop.grid )
output.array <- img$crop( box = crop.grid )
output.array$save( output.filename )
img$close()
rm( img )
gc()
img <- reticulate::r_to_py( 1L )
python
内我最好使用
with
打开图片为了在过程结束时清除它,但我不确定如何使用
reticulate
来实现它.
python
版本:
from PIL import Image
img = Image.open( "/home/user/Desktop/image.jpg" )
output = img.crop( [0,0,100,100] )
output.close()
img.close()
output.array$close()
img$close()
gc() # for good measure
最佳答案
你需要做3件事:
py_env <- py_run_string(
paste(
"from PIL import Image",
"img = Image.open('~/Desktop/image.jpg')",
sep = "\n"
),
convert = FALSE
)
img <- py_env$img
py_run_string("del img")
py_gc <- import("gc")
py_gc$collect()
关于R 网状,如何从内存中清除 python 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44379525/
我正在尝试在 rmarkdown 文档中添加 python block 。我安装了包 reticulate 然后这是我的文档: ```{r, message=FALSE, warning=FALSE,
我正在使用 reticulate R 包并想用它配置 python3,但是无法做到。我尝试了以下代码 library(reticulate) packageVersion("reticulate")
我已经通过 reticulate 使用一些 python 功能创建了一个函数包,特别是使用 PIL 打开图像: image <- "~/Desktop/image.jpg" pil.image <-
我对python比较熟悉,只知道R的基础;所以对于需要“使用 R”的类(class),我非常依赖图书馆,“网状”。 在过去一两个月里,我已经多次使用它,没有任何问题;但是,今天我定义了一个类。我毫无问
source_python得到结果后,我可以关闭或重新启动python控制台吗?如果是这样,怎么办? 假设我关闭/重新启动了 python 控制台,我仍然能够在 R 中访问之前在 source_pyt
我正在使用很棒的新 r 包“reticulate”来合并 Python 和 R,以便能够在 R 中使用数据提供商 (Thomson Reuters Eikon) 的 API,该 API 仅适用于 Py
我看到有人问过这个问题的变体,但没有一个答案能解决我的问题。我使用的是 Windows 10,R 版本 3.6.2,RStudio 版本 1.2.5033,网状版本 1.14 > library(re
我是一名优秀的程序员,十分优秀!