Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. try {
  2. String line = new String();
  3.  
  4. String command = "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 ./tester.py";
  5. Process p = Runtime.getRuntime().exec(command+ " "+id);
  6. p.waitFor();
  7. System.out.println("exit value: "+p.exitValue());
  8. BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
  9.  
  10. if ((line = bri.readLine()) != null) {
  11. x = Integer.parseInt(line);
  12. System.out.println("valore int x : " +x);
  13. }
  14.  
  15. bri.close();
  16. }catch (Exception e){
  17. e.printStackTrace();
  18. }
  19.  
  20. import cv2
  21. import os
  22. import numpy as np
  23. import faceRecognition as fr
  24. import sys
  25.  
  26.  
  27.  
  28. #This module takes images stored in diskand performs face recognition
  29. test_img=cv2.imread('TestImages/imgtotest'+sys.argv[1]+'.jpg')#test_img path
  30. faces_detected,gray_img=fr.faceDetection(test_img)
  31. # print("faces_detected:",faces_detected)
  32.  
  33.  
  34. #Comment belows lines when running this program second time.Since it saves training.yml file in directory
  35. # faces,faceID=fr.labels_for_training_data('trainingImages')
  36. # face_recognizer=fr.train_classifier(faces,faceID)
  37. # face_recognizer.write('trainingData.yml')
  38.  
  39.  
  40. #Uncomment below line for subsequent runs
  41. face_recognizer=cv2.face.LBPHFaceRecognizer_create()
  42. face_recognizer.read('trainingData.yml')#use this to load training data for subsequent runs
  43.  
  44. name={0:"Priyanka",1:"Kangana",2:"Agos",3:"Valaur"}#creating dictionary containing names for each label
  45. returnCode = 0
  46. #forExecuted = -1
  47. for face in faces_detected:
  48. #print("sono qui")
  49. #forExeceuted = 1
  50. (x,y,w,h)=face
  51. roi_gray=gray_img[y:y+h,x:x+h]
  52. label,confidence=face_recognizer.predict(roi_gray)#predicting the label of given image
  53. # print("confidence:",confidence)
  54. # print("label:",label)
  55. fr.draw_rect(test_img,face)
  56. predicted_name=name[label]
  57. if(confidence>37):#If confidence more than 37 then don't print predicted face text on screen
  58. #print("sono qui")
  59. returnCode = -1
  60. continue
  61. returnCode = 1
  62. fr.put_text(test_img,predicted_name,x,y)
  63.  
  64. resized_img=cv2.resize(test_img,(1000,1000))
  65. print(int(func(returnCode)))
  66. #cv2.imshow("face dtecetion tutorial",resized_img)
  67. #cv2.waitKey(0)#Waits indefinitely until a key is pressed
  68. #cv2.destroyAllWindows
  69.  
  70. def func(a):
  71. return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement