Skip to content

Commit

Permalink
New version, displays actual objects instead of just displaying textures
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleySweet committed Jan 17, 2018
1 parent 424b221 commit c111132
Show file tree
Hide file tree
Showing 434 changed files with 23,826 additions and 396 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ public static int Compute(string s, string t)
}

// Step 2
for (int i = 0; i <= n; d[i, 0] = i++)
{
}
for (int i = 0; i <= n; d[i, 0] = i++);
for (int j = 0; j <= m; d[0, j] = j++);

for (int j = 0; j <= m; d[0, j] = j++)
{
}

// Step 3
for (int i = 1; i <= n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public abstract class MediaCaptureFrameProcessor : IDisposable
{
public MediaCaptureFrameProcessor(
protected MediaCaptureFrameProcessor(
MediaFrameSourceFinder mediaFrameSourceFinder,
DeviceInformation videoDeviceInformation,
string mediaEncodingSubtype,
Expand Down Expand Up @@ -86,16 +86,22 @@ async Task<MediaCapture> CreateMediaCaptureAsync()
MemoryPreference = this.memoryPreference
};

var mediaCapture = new MediaCapture();
var tempMediaCapture = new MediaCapture();

await mediaCapture.InitializeAsync(settings);
await tempMediaCapture.InitializeAsync(settings);

this.videoDeviceControllerInitialiser?.Invoke(mediaCapture.VideoDeviceController);
this.videoDeviceControllerInitialiser?.Invoke(tempMediaCapture.VideoDeviceController);

return (mediaCapture);
return (tempMediaCapture);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (this.mediaCapture != null)
{
Expand All @@ -105,10 +111,10 @@ public void Dispose()
}

Action<VideoDeviceController> videoDeviceControllerInitialiser;
string mediaEncodingSubtype;
MediaFrameSourceFinder mediaFrameSourceFinder;
DeviceInformation videoDeviceInformation;
MediaCaptureMemoryPreference memoryPreference;
readonly string mediaEncodingSubtype;
readonly MediaFrameSourceFinder mediaFrameSourceFinder;
readonly DeviceInformation videoDeviceInformation;
readonly MediaCaptureMemoryPreference memoryPreference;
MediaCapture mediaCapture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
public class WordFrameProcessor : MediaCaptureFrameProcessor
{
public List<ActiDetectedWord> Result { get; private set; }
private string m_RequestWord;
public readonly string RequestWord;
private OcrEngine m_OcrEngine;

public WordFrameProcessor(string requestWord, MediaFrameSourceFinder mediaFrameSourceFinder, DeviceInformation videoDeviceInformation, string mediaEncodingSubtype, MediaCaptureMemoryPreference memoryPreference = MediaCaptureMemoryPreference.Cpu) : base(mediaFrameSourceFinder, videoDeviceInformation, mediaEncodingSubtype, memoryPreference)
{
Result = new List<ActiDetectedWord>();
this.m_RequestWord = requestWord;
this.RequestWord = requestWord;
}

protected override async Task<bool> ProcessFrameAsync(MediaFrameReference frameReference)
Expand All @@ -44,20 +44,22 @@ await Task.Run(async () =>
OcrResult ocrResult = await this.m_OcrEngine.RecognizeAsync(bitmap);

if (ocrResult == null)
throw new Exception("Ocr Result is null");
throw new NullReferenceException("Ocr Result is null");

foreach (OcrWord word in ocrResult.Lines.SelectMany(l => l.Words).ToList())
foreach (OcrWord word in ocrResult.Lines.SelectMany(l => l.Words))
{
if ("quarante deux".Equals(m_RequestWord.ToLower()))
if ("quarante deux".Equals(RequestWord.ToLower()))
Result.Add(new ActiDetectedWord(word.Text, word.BoundingRect.X, word.BoundingRect.Y, word.BoundingRect.Width, word.BoundingRect.Height, false));
else if (word.Text.ToLower().Contains(m_RequestWord))
else if (word.Text.ToLower().Equals(RequestWord.ToLower()))
Result.Add(new ActiDetectedWord(word.Text, word.BoundingRect.X, word.BoundingRect.Y, word.BoundingRect.Width, word.BoundingRect.Height, true));
else if (LevenshteinDistance.Compute(m_RequestWord.ToLower(), word.Text.ToLower()) <= 2)
else if (word.Text.ToLower().Contains(RequestWord.ToLower()))
Result.Add(new ActiDetectedWord(word.Text, word.BoundingRect.X, word.BoundingRect.Y, word.BoundingRect.Width, word.BoundingRect.Height, true));
else if (RequestWord.ToLower().Contains(word.Text.ToLower()))
Result.Add(new ActiDetectedWord(word.Text, word.BoundingRect.X, word.BoundingRect.Y, word.BoundingRect.Width, word.BoundingRect.Height, true));
else if (LevenshteinDistance.Compute(RequestWord.ToLower(), word.Text.ToLower()) <= 2)
Result.Add(new ActiDetectedWord(word.Text, word.BoundingRect.X, word.BoundingRect.Y, word.BoundingRect.Width, word.BoundingRect.Height, false));

}


success = Result.Count > 0;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using MediaFrameQrProcessing.VideoDeviceFinders;
using System;
using System.Net;
using System.Threading.Tasks;
using Windows.Media.MediaProperties;

public static class IPAddressScanner
{
public static async void ScanFirstCameraForIPAddress(
public static async Task ScanFirstCameraForIPAddress(
Action<IPAddress> resultCallback,
TimeSpan timeout)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class WordScanner
/// <param name="resultCallback"></param>
/// <param name="timeout"></param>
/// <param name="requestWord"></param>
public static async void ScanFirstCameraForWords(Action<List<ActiDetectedWord>> resultCallback, TimeSpan timeout, string requestWord)
public static async Task ScanFirstCameraForWords(Action<List<ActiDetectedWord>> resultCallback, TimeSpan timeout, string requestWord)
{

List<ActiDetectedWord> result = null;
Expand All @@ -30,7 +30,8 @@ public static async void ScanFirstCameraForWords(Action<List<ActiDetectedWord>>
// around I ended up with a crash in Windows.Media.dll related
// to disposing of the MediaCapture.
// So...this isn't what I wanted but it seems to work better :-(
if (m_FrameProcessor == null)
// We still need to update it case the word has changed, else it w
if (m_FrameProcessor == null || !requestWord.Equals(m_FrameProcessor.RequestWord))
{
var mediaFrameSourceFinder = new MediaFrameSourceFinder();

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified FullScreen-Version/UnityProject/.vs/UnityProject/v15/.suo
Binary file not shown.
Binary file not shown.
63 changes: 47 additions & 16 deletions FullScreen-Version/UnityProject/Assets/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,53 @@
{
using System;
using UnityEngine;
class Constants
static class Constants
{
public static Color PERFECT_MATCH_COLOR = Color.green;
public static Color APPROXIMATE_MATCH_COLOR = Color.yellow;
public static String VALIDATION_TEXT = "okay";
public static String STOP_TEXT = "stop";
public static String WILDCARD = "quarante deux";
public static String SEARCH_KEYWORD = "rechercher";
public static String QRCODE_KEYWORD = "traduire";
public static String SEARCHING_FOR_QR_CODES = "Recherche de QR codes en cours";
public static String HOME_PROMPT = string.Format("Donnez le mot à rechercher. \n Dites '{0}' pour annuler.", STOP_TEXT);
public static String LOOKING_FOR_WORD = "Recherche en cours pour le mot ";
public static String RESET_IN_PROGRESS = "Réinitialisation en cours";
public static String NO_QR_CODE_FOUND = "Aucun QR code trouvé, " + RESET_IN_PROGRESS;
public static Double TIMEOUT = 5;
public static Boolean DEBUG = true;
public static String ERROR_NO_RESULT_FOUND = "ERROR : 0 exact match(es) were found. 0 close match(es) were found for the word";
#region Critical Constants
public static readonly String WILDCARD_HEARD_TEXT = "42";
public static readonly String WILDCARD_TEXT = "quarante deux";
public static readonly String SEARCH_KEYWORD = "rechercher";
public static readonly String QRCODE_KEYWORD = "translate";
public static readonly String QUIT_KEYWORD = "quit";
public static readonly String VALIDATION_KEYWORD = "okay";
public static readonly String STOP_KEYWORD = "stop";
public static readonly Double TIMEOUT = 5;
public static readonly Boolean DEBUG = false;
#endregion

#region
public static readonly String WEBCAM_HAS_INITIALIZED_SUCESSFULLY = "La webcam a été initialisée correctement.";
public static readonly Color32 PERFECT_MATCH_COLOR = Color.green;
public static readonly Color32 APPROXIMATE_MATCH_COLOR = Color.yellow;
public static readonly float DEBUG_PLANE_WIDTH = 0.04700003F;
public static readonly float DEBUG_PLANE_HEIGHT = 0.03750001F;
public static readonly String DEFAULT_VR_DEVICE_NAME = string.Empty;
public static readonly String DEFAULT_MICROPHONE_DEVICE_NAME = string.Empty;
public static readonly String IS_MICROPHONE_RECORDING = "Le Microphone " + (Microphone.IsRecording(DEFAULT_MICROPHONE_DEVICE_NAME) ? "est" : "n'est pas ") + " en train d'enregistrer.";
public static readonly String EXACT_MATCHES_WERE_FOUND = " occurence(s) exacte(s) ont été trouvée(s). \n ";
public static readonly String APPROXIMATE_MATCHES_WERE_FOUND = " occurence(s) proche(s) ont été trouvée(s). \n pour le mot : ";
public static readonly String RESULT_TEXT_RECOGNITION_SENTENCE = "{0}" + EXACT_MATCHES_WERE_FOUND + "{1}" + APPROXIMATE_MATCHES_WERE_FOUND + "'{2}'.";
public static readonly String THE_WORD_YOU_ARE_LOOKING_FOR_IS = "Le mot à rechercher est {0} \n {1}";
public static readonly String PLANE_MESH_NAME = "Plane";
public static readonly String CANVAS_MESH_NAME = "Canvas";
public static readonly String THE_QR_CODE_MEANS = "Le QR code représente : {0}\n Dites '" + STOP_KEYWORD + "' pour retourner au menu";
public static readonly String RESULT_BOX_NAME_PREFIX = "ResultBox";
public static readonly String RESULT_BOX_SHADER_NAME = "UI/Default Font";
public static readonly String LAMBERT_MATERIAL_LOCATION = "/HoloToolkit/Input/Models/Cursor/Materials/lambert1.mat";
public static readonly String TEXT_QUITTING_APPLICATION = "Arrêt de l'application";
public static readonly String FINAL_WORD_SEARCH_PROMPT = String.Format("dites '{1}' pour continuer. \n Dites '{0}' pour annuler", STOP_KEYWORD, VALIDATION_KEYWORD);
public static readonly String SEARCHING_FOR_QR_CODES = "Recherche de QR codes en cours";
public static readonly String SEARCH_PROMPT = string.Format("Donnez le mot à rechercher. \n Dites '{0}' pour annuler.", STOP_KEYWORD);
public static readonly String LOOKING_FOR_WORD = "Recherche en cours pour le mot '{0}'.";
public static readonly String RESET_IN_PROGRESS = "Réinitialisation en cours";
public static readonly String NO_QR_CODE_FOUND = "Aucun QR code trouvé, " + RESET_IN_PROGRESS;
public static readonly String HOME_PROMPT = string.Format("Dites '{0}' pour commencer \n ou '{1}' pour dechiffrer un QR code", SEARCH_KEYWORD, QRCODE_KEYWORD);
public static readonly String ERROR_DISPLAYING_RECTANGLES = "ERREUR : Erreur lors de l'affichage du/des rectangle(s). ";
public static readonly String ERROR_LOOKING_FOR_WORDS = "ERREUR : Erreur lors de la recherche de mots";
public static readonly String ERROR_COMPLETING_DICTATION = "ERREUR : La dictée ne s'est pas terminée correctement: {0}.";
public static readonly String ERROR_NO_INTERNET = "ERREUR : La reconnaissance vocale ne fonctionne pas sans internet.";
public static readonly String ERROR_IN_DICTATION = "ERREUR : La dictée a échoué : {0}; HResult = {1}.";
public static readonly String ERROR_NO_RESULT_FOUND = "ERREUR : aucune occurence exacte ni proche n'ont été trouvées.";
#endregion
}
}
19 changes: 13 additions & 6 deletions FullScreen-Version/UnityProject/Assets/DisplayWebcam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ namespace Assets

public class DisplayWebcam : MonoBehaviour
{
public static Renderer rend;
private static Renderer rend;
public static WebCamTexture tex;

public static int WebcamHeightResolution;
public static int WebcamWidthResolution;

// Use this for initialization
public void Start()
{
if (Constants.DEBUG)
DisplayWebcamPreview();
else
// We need to start the webcam in order to get a correct height.
// Else it would return a 16x16 resolution.
DisplayWebcamPreview();

// If not in debug mode do not display the webcam.
if (!Constants.DEBUG)
{
rend = this.GetComponentInChildren<Renderer>();
rend.enabled = false;
tex.Stop();
}
Debug.Log(Constants.WEBCAM_HAS_INITIALIZED_SUCESSFULLY);
}

private void DisplayWebcamPreview()
Expand All @@ -28,6 +33,8 @@ private void DisplayWebcamPreview()
tex = new WebCamTexture(devices[0].name);
rend.material.mainTexture = tex;
tex.Play();
WebcamHeightResolution = tex.height;
WebcamWidthResolution = tex.width;
}
}
}
Loading

0 comments on commit c111132

Please sign in to comment.