IEnumerator UploadFileCo(string uploadURL) { //Take screen shot yield return(new WaitForEndOfFrame()); Texture2D screenTexture = new Texture2D((int)(FrameCoordinates.size.x - (FrameCoordinates.borderWidth * 2)), (int)(FrameCoordinates.size.y - (FrameCoordinates.borderWidth * 2)), TextureFormat.RGB24, true); //screenTexture.ReadPixels(new Rect(FrameCoordinates.left, FrameCoordinates.bottom, FrameCoordinates.size.x, FrameCoordinates.size.y),0,0); screenTexture.ReadPixels(new Rect(FrameCoordinates.left + FrameCoordinates.borderWidth, FrameCoordinates.bottom + FrameCoordinates.borderWidth, FrameCoordinates.size.x - (FrameCoordinates.borderWidth * 2), FrameCoordinates.size.y - (FrameCoordinates.borderWidth * 2)), 0, 0); //screenTexture.ReadPixels(new Rect(0f, 0f+150, Screen.width, Screen.height-150),0,0); screenTexture.Apply(); //Rotate pictures taken in landscape if (!(Input.deviceOrientation == DeviceOrientation.Portrait)) { Debug.Log("###---ORIENTATION SWITCHED TO LANDSCAPE---###"); Texture2D screenTexture2 = new Texture2D((int)(FrameCoordinates.size.y - (FrameCoordinates.borderWidth * 2)), (int)(FrameCoordinates.size.x - (FrameCoordinates.borderWidth * 2)), TextureFormat.RGB24, true); Color32[] pixels = screenTexture.GetPixels32(); pixels = ImageManipulation.RotateMatrix(pixels, (int)(FrameCoordinates.size.x - (FrameCoordinates.borderWidth * 2)), (int)(FrameCoordinates.size.y - (FrameCoordinates.borderWidth * 2))); screenTexture2.SetPixels32(pixels); screenTexture = screenTexture2; } //Convert image to bytes byte[] pData2 = screenTexture.EncodeToJPG(); //UnityEngine.Object.Destroy(screenTexture); loadScreen.SetActive(true); //Create post request WWWForm postForm = new WWWForm(); string postData = null; //set true for Stroke-Width Transform preprocessing (attempts to remove artifacts that aren't characters) bool sw = false; if (!sw) { postData = "--09sad98as09dhidp0a98soakscajbva12\n" + "Content-Type: application/json; charset=UTF-8\n\n" + "{\"engine\":\"tesseract\"}\n\n" + "--09sad98as09dhidp0a98soakscajbva12\n" + "Content-Type: image/jpeg\n" + "Content-Disposition: attachment; filename=\"attachment.txt\". \n\n"; } else { postData = "--09sad98as09dhidp0a98soakscajbva12\n" + "Content-Type: application/json; charset=UTF-8\n\n" + "{\"engine\":\"tesseract\", \"preprocessors\":[\"stroke-width-transform\"]}\n\n" + "--09sad98as09dhidp0a98soakscajbva12\n" + "Content-Type: image/jpeg\n" + "Content-Disposition: attachment; filename=\"attachment.txt\". \n\n"; } byte[] pData1 = System.Text.Encoding.UTF8.GetBytes(postData.ToCharArray()); string postDataEnd = "\n--09sad98as09dhidp0a98soakscajbva12--\n"; byte[] pData3 = System.Text.Encoding.UTF8.GetBytes(postDataEnd.ToCharArray()); //combine different parts of request into byte array byte[] pDataCom = new byte[pData1.Length + pData2.Length + pData3.Length]; System.Buffer.BlockCopy(pData1, 0, pDataCom, 0, pData1.Length); System.Buffer.BlockCopy(pData2, 0, pDataCom, pData1.Length, pData2.Length); System.Buffer.BlockCopy(pData3, 0, pDataCom, pData1.Length + pData2.Length, pData3.Length); System.Collections.Generic.Dictionary <string, string> headers = new System.Collections.Generic.Dictionary <string, string>(); headers.Add("Content-Type", "multipart/related;boundary=09sad98as09dhidp0a98soakscajbva12"); byte[] pData = System.Text.Encoding.UTF8.GetBytes(postData.ToCharArray()); //Create connection WWW upload = new WWW(uploadURL, pDataCom, headers); yield return(upload); if (upload.error == null) { Debug.Log("\n\n" + System.DateTime.Now.ToString() + ": OCR RESULT: " + upload.text); string result = upload.text.Trim(); result += "\n"; MakeDataset(result); backBtn.SetActive(true); //shareGraph.SetActive(true); editGraph.SetActive(true); //viewGraphs.SetActive(false); takePhoto.SetActive(false); frameCanvas.SetActive(false); } else { Debug.Log("WWW Error: " + upload.error); Debug.Log("WWW Error: " + upload.text); loadScreen.SetActive(false); } }