从R中的图片数据创建数据帧
我需要从图片创建数据帧,即在参数上拆分图片。我使用Azure认知服务从R中的图片数据创建数据帧,r,azure,dataframe,face-recognition,R,Azure,Dataframe,Face Recognition,我需要从图片创建数据帧,即在参数上拆分图片。我使用Azure认知服务 q <- "?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age,gender,smile,headPose,facialHair,glasses,emotion" url1 <- paste( q, sep="") #path to my folder with pict
q <- "?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age,gender,smile,headPose,facialHair,glasses,emotion"
url1 <- paste( q, sep="")
#path to my folder with pictures
pic1="C:/pictures" #here some pictures
library("httr")
#send the request to Face API
# my keys calls FaceRecognition
response = POST(url=url1, body=pic1, add_headers(.headers =
c('Content-Type'='application/octet-stream', 'FaceRecognition'='12345...32')))
result <- content(response)
result
df <- as.data.frame(result)
# pivot the data frame...you need to add package reshape2 for this
library("reshape2")
df2 <- melt(df, id=c("faceId"))
但我想得到像这样的数据帧
然后像这样转置数据帧
如何获得这样的输出
笔记
Azure不是我的灵丹妙药,我以它为例进行实践,如果您知道一种更容易获得所需输出的方法,我将非常感谢您。看起来您正在粘贴一个字符串。“粘贴”接受多个参数,并使用sep将它们连接到单个字符对象中以分隔它们。所以url1只是q,实际上是一个格式错误的url,因为没有协议(例如http://)或url(例如example.com/facerecognitionendpoint)。剩下的就是这样的结果 尝试在粘贴语句中添加url,例如
base <- "https://northeurope.api.cognitive.microsoft.com/face/v1.0/identify"
q <- "?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age,gender,smile,headPose,facialHair,glasses,emotion"
url1 <- paste(base, q, sep = "")
base您的链接是针对microsoft的。如果没有微软,我如何添加我的链接azure人脸识别API由微软提供。其他产品将有自己的端点。您必须查看您希望使用的服务的文档。
Error: id variables not found in data: faceId
base <- "https://northeurope.api.cognitive.microsoft.com/face/v1.0/identify"
q <- "?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age,gender,smile,headPose,facialHair,glasses,emotion"
url1 <- paste(base, q, sep = "")
pic1 <- "C:/pictures/pic1.jpeg"
response <- POST(url = url1, body = upload_file(pic1) ...)