首先,我使用以下代码读取图像:
img<-readPNG(imageLocation)
imageLocation 是使用 path.expand() 扩展后的图像路径
imageLocation = path.expand("~/R/funwithR/data/mero_photoforanalysis.png")
转换为灰度图的操作如下:
img <- 0.2126 * img[, , 1] + 0.7152 * img[, , 2] + 0.0722 * img[, , 3]
最后,错误由以下代码触发:
face_emotion(img)
错误信息如下:
Error in function (type, msg, asError = TRUE) : couldn't connect to host
回答:
我认为问题出在你传递给indico API的格式上。根据indico的文档,API接受的是文件路径作为输入,而不是图像对象。
好消息是,你不需要转换为灰度图。如果你直接运行以下代码,应该可以正常工作:
fer(path.expand("~/R/funwithR/data/mero_photoforanalysis.png"))