OCRWebService/src/com/conordevilly/ocr/webservice/RestService.java
@POST
	@Path("/ocr")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response process(InputStream incomingData) {
		StringBuilder respBuilder = new StringBuilder();
		String encodedData = null;
		String guess = null;
		File data = null;

		//Create the NN if it does not exist, read it 
		if(nn == null){
			nn = PersistanceManager.readNN(new File("nn.data"));
			//If still null, create a new NN
			if(nn == null){
				nn = new NeuralNetwork(10, 26);
			}
		}

		try {
			//Read the input
			BufferedReader in = new BufferedReader(new InputStreamReader(incomingData));
			String line = null;
			while ((line = in.readLine()) != null) {
				respBuilder.append(line);
			}

			//Put input into json object
			JSONObject json = new JSONObject(respBuilder.toString());
			
			//Get encoded data, decode it and turn into an image
			encodedData = (String) json.get("fileData");
			data = convStringToFile(encodedData);
			BufferedImage input = ImageIO.read(data);
			
			//Run the image through the NN and get a guess
			guess = nn.processMultiImage(input);
		}catch(IOException e){
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}

		//Return the guess
		return Response.status(200).entity(guess).build();
	}
/*
	 * Service to allow NN to guess over the internet
	 * Reads in JSON String
	 * This string contains a Base64 encoded string that, when decoded, is an Image
	 * This image is ran through the NN and a guess is returned
	 */
Service to allow NN to guess over the internet
Reads in JSON String
This string contains a Base64 encoded string that, when decoded, is an Image
This image is ran through the NN and a guess is returned
Service to allow NN to guess over the internet Reads in JSON String This string contains a Base64 encoded string that when decoded is an Image This image is ran through the NN and a guess is returned
@POST
	@Path("/ocr")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response process(InputStream incomingData) {
		StringBuilder respBuilder = new StringBuilder();
		String encodedData = null;
		String guess = null;
		File data = null;
		if(nn == null){
			nn = PersistanceManager.readNN(new File("nn.data"));
			if(nn == null){
				nn = new NeuralNetwork(10, 26);
			}
		}
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(incomingData));
			String line = null;
			while ((line = in.readLine()) != null) {
				respBuilder.append(line);
			}
			JSONObject json = new JSONObject(respBuilder.toString());
			encodedData = (String) json.get("fileData");
			data = convStringToFile(encodedData);
			BufferedImage input = ImageIO.read(data);
			guess = nn.processMultiImage(input);
		}catch(IOException e){
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return Response.status(200).entity(guess).build();
	}
@ POST @ Path ( "/ocr" ) @ Consumes ( MediaType . APPLICATION_JSON ) public Response process ( InputStream incomingData ) { StringBuilder respBuilder = new StringBuilder ( ) ; String encodedData = null ; String guess = null ; File data = null ; if ( nn == null ) { nn = PersistanceManager . readNN ( new File ( "nn.data" ) ) ; if ( nn == null ) { nn = new NeuralNetwork ( 10 , 26 ) ; } } try { BufferedReader in = new BufferedReader ( new InputStreamReader ( incomingData ) ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { respBuilder . append ( line ) ; } JSONObject json = new JSONObject ( respBuilder . toString ( ) ) ; encodedData = ( String ) json . get ( "fileData" ) ; data = convStringToFile ( encodedData ) ; BufferedImage input = ImageIO . read ( data ) ; guess = nn . processMultiImage ( input ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } return Response . status ( 200 ) . entity ( guess ) . build ( ) ; }
Service to allow NN to guess over the internet
 Reads in JSON String
 This string contains a Base64 encoded string that, when decoded, is an Image
 This image is ran through the NN and a guess is returned
Service to allow NN to guess over the internet Reads in JSON String This string contains a Base64 encoded string that when decoded is an Image This image is ran through the NN and a guess is returned
//Create the NN if it does not exist, read it  //If still null, create a new NN //Read the input //Put input into json object //Get encoded data, decode it and turn into an image //Run the image through the NN and get a guess //Return the guess