示例#1
0
        public static RecogReply PredictionFunc(Guid id, int timeBudgetInMS, RecogRequest req)
        {
            byte[] imgBuf      = req.Data;
            byte[] imgType     = System.Text.Encoding.UTF8.GetBytes("jpg");
            Guid   imgID       = BufferCache.HashBufferAndType(imgBuf, imgType);
            string imgFileName = imgID.ToString() + ".jpg";

            string filename = Path.Combine(saveImageDir, imgFileName);

            if (!File.Exists(filename))
            {
                FileTools.WriteBytesToFileConcurrent(filename, imgBuf);
            }

            Stopwatch timer = Stopwatch.StartNew();

            CaffeModel.SetDevice(gpu);
            string resultString = predictor.Predict(filename);

            timer.Stop();

            File.Delete(filename);
            numImageRecognized++;
            Console.WriteLine("Image {0}:{1}:{2}: {3}", numImageRecognized, imgFileName, timer.Elapsed, resultString);
            return(VHubRecogResultHelper.FixedClassificationResult(resultString, resultString));
        }
示例#2
0
        public static RecogReply PredictionFunc(Guid id, int timeBudgetInMS, RecogRequest req)
        {
            byte[] imgBuf      = req.Data;
            byte[] imgType     = System.Text.Encoding.UTF8.GetBytes("jpg");
            Guid   imgID       = BufferCache.HashBufferAndType(imgBuf, imgType);
            string imgFileName = imgID.ToString() + ".jpg";

            string resultString = "";

            try
            {
                string filename = Path.Combine(saveImageDir, imgFileName);
                if (!File.Exists(filename))
                {
                    FileTools.WriteBytesToFileConcurrent(filename, imgBuf);
                }

                Directory.SetCurrentDirectory(rootDir);
                var processStartInfo = new ProcessStartInfo
                {
                    FileName  = @"main.bat",
                    Arguments = filename,
                    //RedirectStandardOutput = true,
                    UseShellExecute = false
                };
                var process = Process.Start(processStartInfo);
                //var resultString = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                if (File.Exists(filename + ".caption"))
                {
                    resultString = File.ReadAllLines(filename + ".caption")[0];
                }

                File.Delete(filename);
                File.Delete(filename + "_1.txt");
                File.Delete(filename + "_1.txt.detections.prec.txt");
                File.Delete(filename + "_1.txt.detections.sc.txt");
                File.Delete(filename + "_1.txt.img.dmsm.fea");
                File.Delete(filename + ".caption");
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, e.Message);
                resultString = "Service exception. Please try again.";
            }
            numImageRecognized++;
            Console.WriteLine("Image {0}: {1}", numImageRecognized, resultString);
            return(VHubRecogResultHelper.FixedClassificationResult(resultString, resultString));
        }
示例#3
0
        public static RecogReply PredictionFunc(Guid id, int timeBudgetInMS, RecogRequest req)
        {
            byte[] data         = req.Data;
            byte[] dataType     = System.Text.Encoding.UTF8.GetBytes("mllr");
            Guid   dataID       = BufferCache.HashBufferAndType(data, dataType);
            string dataFileName = dataID.ToString() + ".mllr";

            string filename = Path.Combine(saveDataDir, dataFileName);

            if (!File.Exists(filename))
            {
                FileTools.WriteBytesToFileConcurrent(filename, data);
            }

            Directory.SetCurrentDirectory(rootDir);
            var processStartInfo = new ProcessStartInfo
            {
                FileName  = @"main.bat",
                Arguments = filename,
                //RedirectStandardOutput = true,
                UseShellExecute = false
            };
            var process = Process.Start(processStartInfo);

            //var resultString = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            string resultString = "";

            if (File.Exists(filename + ".mllr"))
            {
                resultString = File.ReadAllText(filename + ".mllr");
            }

            File.Delete(filename);
            File.Delete(filename + ".mllr");

            numDataProcessed++;
            Console.WriteLine("Data {0}: {1}", numDataProcessed, resultString);
            return(VHubRecogResultHelper.FixedClassificationResult(resultString, resultString));
        }
示例#4
0
        public static RecogReply PredictionFunc(Guid id, int timeBudgetInMS, RecogRequest req)
        {
            byte[] imgBuf      = req.Data;
            byte[] imgType     = System.Text.Encoding.UTF8.GetBytes("jpg");
            Guid   imgID       = BufferCache.HashBufferAndType(imgBuf, imgType);
            string imgFileName = imgID.ToString() + ".jpg";

            string filename = Path.Combine(saveImageDir, imgFileName);

            if (!File.Exists(filename))
            {
                FileTools.WriteBytesToFileConcurrent(filename, imgBuf);
            }

            string result_words   = wordDetector.DetectWords(filename);
            string result_feature = wordDetector.ExtractFeature(filename);

            string resultString = result_words + "\n" + result_feature;

            File.Delete(filename);
            numImageRecognized++;
            Console.WriteLine("Image {0}: {1}", numImageRecognized, resultString);
            return(VHubRecogResultHelper.FixedClassificationResult(resultString, resultString));
        }