RããGoogle Cloud Vision APIã使ã
Google Cloud Vision APIãé«æ§è½ãããã®ã§ä½¿ãããã®ã ãç§ã¯Rãã使ããªãã®ã§Rãã使ãã
ã¨ããããææã¡ã®ãã®ç»åã®OCRããããã
åæºåã¨ãã¦APIãã¼ã®åå¾ãªã©ãããã®ã§ä»¥ä¸ãåèã«ããããã
http://qiita.com/takaheraw@github/items/e2d8ac9edad4655596a2
ã³ã¼ãã¯ä»¥ä¸ã®éãã
getResult <- function(f, type = "TEXT_DETECTION"){ library("httr") library("base64enc") CROWD_VISION_KEY <- "ããªãã®ãã¼" u <- paste0("https://vision.googleapis.com/v1/images:annotate?key=", CROWD_VISION_KEY) img <- readBin(f, "raw", file.info(f)[1, "size"]) base64_encoded <- base64encode(img) body <- list(requests = list(image = list(content = base64_encoded), features = list(type = type, maxResults = 10)) ) res <- POST(url = u, encode = "json", body = body, content_type_json()) }
çµæã¯ä»¥ä¸ã®éããã¡ãã£ã¨è¨ã£ã¦ãã
f_satoyanagi <- "satoyanagi.png" res <- getResult(f_satoyanagi, "TEXT_DETECTION") content(res)$responses[[1]]$textAnnotations[[1]]$description [1] "ãã¼ã¿è㤠ã³ã\nãã©ããã¸ããã\nä¸\n"
ã»ãã«ãè²ã ã§ãã
ãã¨ãã°ç©ä½èªèãã§ããã
ã好ã¿ç¼ããèªèããã¦ã¿ããã
f_okonomiyaki <- "okonomiyaki.jpg" res2 <- getResult(f_okonomiyaki, "LABEL_DETECTION") jsonlite::fromJSON(content(res2, as = "text"))$responses$labelAnnotations
ã¡ããã¨ã好ã¿ç¼ããåè£ã«ã§ã¦ããã
[[1]] mid description score 1 /m/02q08p0 dish 0.9867435 2 /m/02wbm food 0.9811904 3 /m/02ln79 yakisoba 0.8415857 4 /m/0dxn2 roasting 0.7471840 5 /m/0772h spaghetti 0.7463352 6 /m/012x_n okonomiyaki 0.7116117 7 /m/09y2k2 italian food 0.6926621 8 /m/0f4s2w vegetable 0.5964628 9 /m/07xgrh ingredient 0.5623973
ä¸å¿ããããç¼ããèªèããã¦ã¿ãã
f_gero <- "monjayaki.jpg" res3 <- getResult(f_gero, "LABEL_DETECTION") jsonlite::fromJSON(content(res3, as = "text"))$responses$labelAnnotations
ä¿¡ããããªããã¨ã«ããããç¼ãã§ããé£ã¹ç©ã¨ãã¦èªèãããããã«åè£ã«ããåºã¦ããã
ããããªGoogleã
[[1]] mid description score 1 /m/018_z5 meat pie 0.9999765 2 /m/02wbm food 0.9927497 3 /m/02q08p0 dish 0.9914593 4 /m/0krfg meal 0.9097335 5 /m/02ln79 yakisoba 0.8457233 6 /m/01_545 jambalaya 0.7069302 7 /m/0hz4q breakfast 0.6837853 8 /m/020t4k stuffing 0.6493556 9 /m/0f010_ monjayaki 0.6427853 10 /m/09y2k2 italian food 0.6076508
Enjoy!!