forked from pachyderm/pachyderm
/
dominant_color.go
63 lines (50 loc) · 1.3 KB
/
dominant_color.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"flag"
"fmt"
"os"
"os/exec"
"github.com/OwnLocal/PipeDream/aws"
"github.com/prometheus/common/log"
)
// Text file that has all the image urls
var images_file = flag.String("images_file", "", "path to the s3 urls")
var aws_bucket_name = flag.String("aws_bucket_name", "", "s3 bucket")
func usageAndExit(msg string) {
fmt.Fprintln(os.Stderr, msg)
fmt.Println("Flags:")
flag.PrintDefaults()
os.Exit(2)
}
func main() {
flag.Parse()
file, err := os.Open(string(*images_file))
if err != nil {
log.Error(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
// Read the source text file line by line
for scanner.Scan() {
fileName := scanner.Text()
// Setup the s3 file object based on file name and bucket flag
file := aws.S3Type{Bucket: *aws_bucket_name, FileName: fileName, ContentType: "image"}
// Download the input file
err := aws.Download(file)
if err != nil {
log.Error(err)
}
// Call the c++ algorithm on the file
cmd := fmt.Sprintf("/home/dominantColor %s ", fileName)
output, err := exec.Command("sh", "-c", cmd).CombinedOutput()
if err != nil {
log.Error(string(output))
}
// Print the results of the dominant colors
fmt.Println(fileName, "|", string(output))
}
if err := scanner.Err(); err != nil {
log.Error(err)
}
}