Exemplo n.º 1
0
func main() {
	config_json, _ := json.Marshal(config)
	log.Printf("Server config: %s \n", config_json)

	mongoConfig := m.MongoConfig{
		Host:     config.MongoDBServer.Host,
		Port:     config.MongoDBServer.Port,
		Database: config.MongoDBServer.Database,
	}

	mongo, err := m.NewMongo(&mongoConfig)

	if err != nil {
		myFatal("Connect to mongodb server Error. err: = %v", err)
	} else {
		log.Printf("Connect to mongodb [%v]: %s, db: %s.", mongo.Connected, mongo.ServerUrl, mongo.DatabaseName)
	}

	restConfig := api.RESTfulConfig{
		Port:          config.Server.Port,
		FileServerURL: config.FileServer.URL,
		Mongo:         mongo,
	}

	restService := api.CreateService(&restConfig)
	err = restService.Serve()
	if err != nil {
		myFatal("Server start error!!! err: ", err)
	}

	defer shutdown()

}
Exemplo n.º 2
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU() * 2)

	config_json, _ := json.Marshal(config)
	log.Printf("Server config: %s \n", config_json)

	mongoConfig := m.MongoConfig{
		Host:     config.MongoDBServer.Host,
		Port:     config.MongoDBServer.Port,
		Database: config.MongoDBServer.Database,
	}

	mongo, err := m.NewMongo(&mongoConfig)
	if err != nil {
		myFatal("Connect to mongodb server Error. err: = %v", err)
	} else {
		log.Printf("Connect to mongodb [%v]: %s, db: %s.", mongo.Connected, mongo.ServerUrl, mongo.DatabaseName)
	}
	defer shutdown()

	mongo.Session.SetCursorTimeout(0)
	mongo.Session.SetBatch(1000)

	taskPool = new(common.TaskPool)
	taskPool.Init(&common.TaskPoolConfig{
		ConnectionsPerServer: config.ConnectionsPerServer,
		Servers:              config.FaceRecServers,
	})

	go taskPool.Start()
	defer taskPool.Stop()

	image := model.ImageInfo{}
	nNeedProcess := mongo.ImageFaceUncheckedOrNilCount()
	log.Printf("Unchecked images count is: %d.", nNeedProcess)
	wg.Add(nNeedProcess)
	iter := mongo.ImageFaceUncheckedOrNil()
	defer iter.Close()
	for iter.Next(&image) {
		img := image
		taskPool.AddTask(func(p pool.Pool) error {
			defer wg.Done()
			procImage(&img, mongo, p)
			return nil
		})
	}
	wg.Wait()
}
Exemplo n.º 3
0
func main() {
	config_json, _ := json.Marshal(config)
	log.Printf("Server config: %s \n", config_json)

	mongoConfig := m.MongoConfig{
		Host:     config.MongoDBServer.Host,
		Port:     config.MongoDBServer.Port,
		Database: config.MongoDBServer.Database,
	}

	mongo, err := m.NewMongo(&mongoConfig)
	if err != nil {
		myFatal("Connect to mongodb server Error. err: = %v", err)
	} else {
		log.Printf("Connect to mongodb [%v]: %s, db: %s.", mongo.Connected, mongo.ServerUrl, mongo.DatabaseName)
	}
	defer shutdown()

	mongo.Session.SetCursorTimeout(0)
	mongo.Session.SetBatch(10000)

	iter := mongo.ImageFaceChecked(true)
	has_image := true
	for {
		if has_image == false {
			break
		}
		wg.Add(JOBS)
		for i := 0; i < JOBS; i++ {
			image := model.ImageInfo{}
			if iter.Next(&image) {
				var curr_count *int
				curr_base_dir := ""
				if image.Has_face == true {
					log.Printf("FACE FIlE: %s", image.File_path)
					curr_count = &has_face_image_cnt
					curr_base_dir = filepath.Join(config.TargetDirPath, HAS_FACE_FILE_DIR)
				} else {
					log.Printf("NO FACE File: %s", image.File_path)
					curr_count = &no_face_image_cnt
					curr_base_dir = filepath.Join(config.TargetDirPath, NO_FACE_FILE_DIR)
				}
				dir := strconv.Itoa(*curr_count / FILES_PER_DIR)
				destDir := filepath.Join(curr_base_dir, dir)
				if *curr_count%FILES_PER_DIR == 0 {
					created, err := utils.Mkdirp(destDir)
					if err != nil {
						log.Printf("create path error. path: %s, err: %v", destDir, err)
					}
					if created {
						log.Printf("create path OK. path: %s", destDir)
					}
				}
				go createLink(image.File_path, destDir)
				*curr_count++
			} else {
				has_image = false
				break
			}
		}
		wg.Wait()
	}
	iter.Close()
}
Exemplo n.º 4
0
func main() {

	config_json, _ := json.Marshal(config)
	log.Printf("Server config: %s \n", config_json)

	mongoConfig := m.MongoConfig{
		Host:     config.MongoDBServer.Host,
		Port:     config.MongoDBServer.Port,
		Database: config.MongoDBServer.Database,
	}

	mongo, err := m.NewMongo(&mongoConfig)
	if err != nil {
		myFatal("Connect to mongodb server Error. err: = %v", err)
	} else {
		log.Printf("Connect to mongodb [%v]: %s, db: %s.", mongo.Connected, mongo.ServerUrl, mongo.DatabaseName)
	}
	defer shutdown()

	mongo.Session.SetCursorTimeout(0)
	mongo.Session.SetBatch(10000)

	taskPool = new(common.TaskPool)
	taskPool.Init(&common.TaskPoolConfig{
		ConnectionsPerServer: config.ConnectionsPerServer,
		Servers:              config.FaceRecServers,
	})

	go taskPool.Start()
	defer taskPool.Stop()

	app := cli.NewApp()
	app.Name = "check_face"
	app.Usage = "check face in image"

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "name, n",
			Value: "",
			Usage: "name of image file.",
		},
	}

	app.Action = func(c *cli.Context) {
		name := c.String("name")
		if len(name) == 0 {
			println("name are required.")
			cli.ShowAppHelp(c)
			return
		}
		iter := mongo.ImageByName(name)
		image := model.ImageInfo{}
		for iter.Next(&image) {
			wg.Add(1)
			img := image
			log.Printf("Found image. image: %v", img)
			taskPool.AddTask(func(p pool.Pool) error {
				procImage(&img, mongo, p)
				wg.Done()
				return nil
			})
			wg.Wait()
		}
		iter.Close()
	}

	app.Run(os.Args)
}