library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory
library("Matrix")
library("jpeg")
library("raster")
library("colorspace")
library(readr)
library("e1071")
library("irlba")
library("xgboost")
library("rgl")
system("ls ../input")
train_photo_to_biz_ids <- read_csv("../input/train_photo_to_biz_ids.csv")
train<-read_csv("../input/train.csv")
train_photo_to_biz_ids<-train_photo_to_biz_ids[order(train$business_id),]
indices<-sample(nrow(train),1)
image_list=list()
for (i in seq_along(indices)) {
    cmd <- paste0("../input/train_photos/", train_photo_to_biz_ids$photo_id[i], ".jpg")
    cat("> ", cmd, "\n")
    system(cmd)
    image_list[[i]]=readJPEG(cmd)
}
train1<-as.data.frame(t(sapply(image_list,function(x) { 
  x<-x[(dim(x)[1]-50):(dim(x)[1]-25),(dim(x)[2]-50):(dim(x)[2]-25),] 
c(rowMeans(x[,,1]),colMeans(x[,,1]),
  rowMeans(x[,,2]),colMeans(x[,,2]),
  rowMeans(x[,,3]),colMeans(x[,,3]))})))
  
  str(train1)
