Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed 'OnCapturedPhotoToDisk' to 'OnCapturedPhotoToMemory'. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 9 additions & 21 deletions Assets/Scripts/Hud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Hud : MonoBehaviour
public Text DiagnosticPanel;

PhotoCapture _photoCaptureObject = null;
Resolution _cameraResolution;
IEnumerator coroutine;

public string _subscriptionKey = "< Computer Vision Key goes here !!!>";
Expand Down Expand Up @@ -54,12 +55,12 @@ void OnPhotoCaptureCreated(PhotoCapture captureObject)
{
_photoCaptureObject = captureObject;

Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
_cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

CameraParameters c = new CameraParameters();
c.hologramOpacity = 0.0f;
c.cameraResolutionWidth = cameraResolution.width;
c.cameraResolutionHeight = cameraResolution.height;
c.cameraResolutionWidth = _cameraResolution.width;
c.cameraResolutionHeight = _cameraResolution.height;
c.pixelFormat = CapturePixelFormat.BGRA32;

captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
Expand All @@ -76,12 +77,7 @@ private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
{
if (result.success)
{
string filename = string.Format(@"terminator_analysis.jpg");
string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename);

//doing this to get formatted image
_photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);

_photoCaptureObject.TakePhotoAsync(OnCapturePhotoToMemory);
}
else
{
Expand All @@ -90,17 +86,16 @@ private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
}
}

void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result)
void OnCapturePhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame frame)
{
if (result.success)
{
string filename = string.Format(@"terminator_analysis.jpg");
string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename);
var texture = new Texture2D(_cameraResolution.width, _cameraResolution.height);
frame.UploadImageDataToTexture(texture);

byte[] image = File.ReadAllBytes(filePath);
byte[] image = texture.EncodeToPNG();
GetTagsAndFaces(image);
ReadWords(image);

}
else
{
Expand All @@ -110,13 +105,6 @@ void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result)
_photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
}


// Update is called once per frame
void Update()
{

}

void AnalyzeScene()
{
InfoPanel.text = "CALCULATION PENDING";
Expand Down