이미지 인식을 수행하는 프로그램을 구현하고 싶습니다. 이미지가 로컬에서 처리 중이면 처리 할 다른 컴퓨터로 보내서 Thread.sleep (1000)을 설정하고 첫 번째 이미지가 로컬에서 처리되고 other가 localprocessing 변수가 false로 설정되기 전에 보낼 것이라고 예상합니다. 나는 그것이 순차적으로 작동하고 실현동시에 여러 Asyntask 실행
private class ProcessImageTask extends AsyncTask<ImageItem, Void, ImageItem>{
@Override
protected ImageItem doInBackground(ImageItem... params) {
if(localProcessing==false){
//**************processing locally*****************
localProcessing = true;
try {
Bitmap bm = BitmapFactory.decodeFile(params[0].getBitmap());
Bitmap croppedBitmap = getBitmap(getApplicationContext(), INPUT_SIZE, bm);
final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap);
String resultStr = results.toString();
String trimResult = resultStr.substring(resultStr.indexOf("[")+1,resultStr.indexOf("]")).trim();
String localId = params[0].getId();
trimResult = trimResult.substring(0,trimResult.indexOf(")")) + " likely)";
Bitmap thumbnail = getBitmap(getApplicationContext(), 50, bm);
ImageItem tmp = new ImageItem(localId, imgToString(thumbnail), trimResult);
Thread.currentThread();
Thread.sleep(1000);
localProcessing = false;
return tmp;
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
//****************processing on server*************************
try {
String ip = strIP;
int port = 8195;
Bitmap bm = BitmapFactory.decodeFile(params[0].getBitmap());
Bitmap croppedBitmap = getBitmap(getApplicationContext(), INPUT_SIZE, bm);
String encodedImage = "/ID-BEGIN/" + ID + "/ID-END" + imgToString(croppedBitmap);
try {
//**********Send request to server*********
Socket socket = new Socket(ip,port);
DataInputStream dis = new DataInputStream(socket.getInputStream());
DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
byte [] messageToServer = encodedImage.getBytes();
dout.writeInt(messageToServer.length);
dout.write(messageToServer);
//Receive response from server
int length = dis.readInt();
if(length>0) {
byte [] message = new byte[length];
dis.readFully(message, 0, message.length);
String response = new String(message);
//Handler updateHandler.post(new updateUIThread(response));
Bitmap thumbnail = getBitmap(getApplicationContext(), 50, bm);
ImageItem tmp = new ImageItem(params[0].getId(),imgToString(thumbnail), extractServerMessage(response)+"@@");
return tmp;
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(ImageItem imageItem) {
super.onPostExecute(imageItem);
}
}
, 당신은 내가 해결하는 방법을 말해와 같은 시간과 같은 다른 작업 작업도 나는 Thread.sleep를 설정하시기 바랍니다 수 있습니다.
정말 고마워요.
이 작업을 어떻게 실행합니까? –