Example #1
0
        /// <summary>
        /// Send the LPImageData to the NodeJS and the return the resulting OpenALPR data with callback
        /// </summary>
        /// <param name="pImageData">Location and the image data</param>
        /// <param name="detectedPlatesCB"> <see cref="DetectedPlatesHandler"/> </param>
        /// <returns><see cref="Task"/></returns>
        public async Task Detect(LPImageData pImageData, DetectedPlatesHandler detectedPlatesCB)
        {
            StorageFolder outputFolder = ApplicationData.Current.LocalFolder;
            int           r            = Interlocked.Increment(ref totalProcessed);
            DateTime      dt           = DateTime.UtcNow;
            string        id           = dt.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); /*create unique file name based on the current date and the count*/

            id  = id.Replace(" ", "");
            id  = id.Replace("/", "");
            id  = id.Replace(":", "");
            id  = id.Replace(".", "");
            id += r;

            StorageFile outputFile = await outputFolder.CreateFileAsync(@"test_pics_out\" + id + ".jpg", CreationCollisionOption.ReplaceExisting);

            SaveSoftwareBitmapToFile(pImageData.lpImage, outputFile);

            var openALPR = new Task <OpenAlprData>(() => UseOpenAlpr(outputFile, pImageData));

            openALPR.Start();
            openALPR.Wait();

            var openALPR_result = openALPR.Result;

            detectedPlatesCB(openALPR_result, pImageData.lpImage, (openALPR_result != null) ? 0 : 1);
        }
Example #2
0
 /// <summary>
 /// Send the LPImageData to the NodeJS and then processes it. Which is just taking the most confident plate that is been detected by the OpenALPR
 /// </summary>
 /// <param name="lpImageData"> Location and the image data </param>
 /// <param name="detectedPlateHandlerGeoCoord"> Callback of the most confident plate with the location and the image itself <see cref="DetectedPlateHandlerGeoCoord"/> </param>
 /// <returns><see cref="Task"/></returns>
 public async Task DetectAndProcess(LPImageData lpImageData, DetectedPlateHandlerGeoCoord detectedPlateHandlerGeoCoord)
 {
     await Detect(lpImageData, (OpenAlprData openAlprData, SoftwareBitmap bitmap, int err) =>
     {
         string final_plate = openAlprData.GetMostConfidentPlate().First;
         detectedPlateHandlerGeoCoord(new DetectedLpData(final_plate, lpImageData.lat, lpImageData.lon, bitmap), err);
     });
 }
Example #3
0
 /// <summary>
 /// Enqueue new LPImageData
 /// </summary>
 /// <param name="lPImageData"></param>
 public void Enqueue(LPImageData lPImageData)
 {
     lock (_lock)
     {
         if (GetCount() <= limit)
         {
             pool.Enqueue(lPImageData);
         }
         else
         {
             throw new OutOfMemoryException();
         }
     }
 }
Example #4
0
        /// <summary>
        /// Sends the given storage file with the LPImageData combined to the NodeJS server
        /// </summary>
        /// <param name="storageFile"> Image file that possibly contains the license plate of a car  </param>
        /// <param name="pImageData"> This contains the location the image, lat and lon, lpImage is not used  </param>
        /// <returns>OpenAlprData that contains the detected plate from an image <see cref="OpenAlprData"/></returns>
        private OpenAlprData UseOpenAlpr(StorageFile storageFile, LPImageData pImageData)
        {
            string CT       = "file";
            string fullPath = storageFile.Path;

            FormUpload.FileParameter f = null;
            for (int i = 1; i < 10; i++)
            {
                try
                {   /*Try to read from a file until you succeed*/
                    f = new FormUpload.FileParameter(File.ReadAllBytes(fullPath), storageFile.Name, "multipart/form-data");
                    break;
                }
                catch (IOException e)
                {
                    Thread.Sleep(1000 * i);
                    Debug.WriteLine("File Load Exception OPENALPR " + i + " : " + e.ToString());
                }
            }

            /*Build the post request*/
            Dictionary <string, object> d = new Dictionary <string, object>();

            d.Add(CT, f);
            d.Add("detected_lat", pImageData.lat);
            d.Add("detected_lon", pImageData.lon);

            string ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; /* I Don't know what this does*/
            var    wr = FormUpload.MultipartFormDataPost("http://localhost:8081/file_upload_alpr", ua, d);


            WebResponse wresp  = null;
            string      result = "";

            try
            {
                Stream       stream2 = wr.GetResponseStream();
                StreamReader reader2 = new StreamReader(stream2);
                result = reader2.ReadToEnd();
                Debug.WriteLine(string.Format("File uploaded {0}, server response is: {1}", "http://localhost:8081/file_upload_alpr", result));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error uploading file", ex);
                if (wresp != null)
                {
                    wresp.Close();
                    wresp = null;
                }
            }
            finally
            {
                wr = null;
            }
            /*Build the response as a OpenAlprData*/
            JsonObject   jsonObject;
            OpenAlprData openAlprData = new OpenAlprData();

            if (JsonObject.TryParse(result, out jsonObject))
            {
                openAlprData.Parse(jsonObject);
            }
            return(openAlprData);
        }