Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. public abstract class CameraActivity extends AppCompatActivity implements OnImageAvailableListener, Camera.PreviewCallback, CompoundButton.OnCheckedChangeListener, View.OnClickListener {
  2. //////////////////////////////////////////////////////////////////////////////
  3. String address = null , name=null;
  4.  
  5. BluetoothAdapter myBluetooth = null;
  6. BluetoothSocket btSocket = null;
  7. Set<BluetoothDevice> pairedDevices;
  8. static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  9. //////////////////////////////////////////////////////////////////////////////
  10. private static final Logger LOGGER = new Logger();
  11.  
  12. private static final int PERMISSIONS_REQUEST = 1;
  13.  
  14. private static final String PERMISSION_CAMERA = Manifest.permission.CAMERA;
  15.  
  16. ...
  17.  
  18. @Override
  19. protected void onCreate(final Bundle savedInstanceState) {
  20. LOGGER.d("onCreate " + this);
  21. super.onCreate(null);
  22. //////////////////////////////////////////////////////////////////////////////
  23. try {setw();} catch (Exception e) {}
  24. //////////////////////////////////////////////////////////////////////////////
  25. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  26.  
  27. setContentView(R.layout.activity_camera);
  28. Toolbar toolbar = findViewById(R.id.toolbar);
  29. setSupportActionBar(toolbar);
  30. getSupportActionBar().setDisplayShowTitleEnabled(false);
  31.  
  32. if (hasPermission()) {
  33. setFragment();
  34. } else {
  35. requestPermission();
  36. }
  37.  
  38. ...
  39.  
  40. ...
  41.  
  42. }
  43. //////////////////////////////////////////////////////////////////////////////
  44. @SuppressLint("ClickableViewAccessibility")
  45. private void setw() throws IOException {
  46. bluetooth_connect_device();
  47. }
  48.  
  49. private void bluetooth_connect_device() throws IOException
  50. {
  51. try
  52. {
  53. myBluetooth = BluetoothAdapter.getDefaultAdapter();
  54. address = myBluetooth.getAddress();
  55. pairedDevices = myBluetooth.getBondedDevices();
  56. if (pairedDevices.size()>0)
  57. {
  58. for(BluetoothDevice bt : pairedDevices)
  59. {
  60. address=bt.getAddress().toString();name = bt.getName().toString();
  61. Toast.makeText(getApplicationContext(),"Connected", Toast.LENGTH_SHORT).show();
  62.  
  63. }
  64. }
  65.  
  66. }
  67. catch(Exception we){}
  68. myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
  69. BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
  70. btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
  71. btSocket.connect();
  72. try {}
  73. catch(Exception e){}
  74. }
  75.  
  76. public void write(String s) throws IOException {
  77. btSocket.getOutputStream().write(s.getBytes());
  78. }
  79.  
  80. //////////////////////////////////////////////////////////////////////////////
  81.  
  82. public synchronized void draw(final Canvas canvas) throws IOException, InterruptedException {
  83. final boolean rotated = sensorOrientation % 180 == 90;
  84. final float multiplier =
  85. Math.min(
  86. canvas.getHeight() / (float) (rotated ? frameWidth : frameHeight),
  87. canvas.getWidth() / (float) (rotated ? frameHeight : frameWidth));
  88. frameToCanvasMatrix =
  89. ImageUtils.getTransformationMatrix(
  90. frameWidth,
  91. frameHeight,
  92. (int) (multiplier * (rotated ? frameHeight : frameWidth)),
  93. (int) (multiplier * (rotated ? frameWidth : frameHeight)),
  94. sensorOrientation,
  95. false);
  96. for (final TrackedRecognition recognition : trackedObjects) {
  97. final RectF trackedPos = new RectF(recognition.location);
  98.  
  99. getFrameToCanvasMatrix().mapRect(trackedPos);
  100. boxPaint.setColor(recognition.color);
  101.  
  102. float cornerSize = Math.min(trackedPos.width(), trackedPos.height()) / 8.0f;
  103. canvas.drawRoundRect(trackedPos, cornerSize, cornerSize, boxPaint);
  104.  
  105. final String labelString =
  106. !TextUtils.isEmpty(recognition.title)
  107. ? String.format("%s %.0f %.0f %.2f", recognition.title, trackedPos.centerX(), trackedPos.centerY(), (100 * recognition.detectionConfidence))
  108. : String.format("%.2f", (100 * recognition.detectionConfidence));
  109.  
  110. borderedText.drawText(
  111. canvas, trackedPos.left + cornerSize, trackedPos.top, labelString + '%' , boxPaint);
  112. //////////////////////////////////////////////////////////////////////////////
  113. if(recognition.title == "person" && (100 * recognition.detectionConfidence) > 40)
  114. {
  115. cameraActivity.write(Integer.toString(Math.round(trackedPos.centerY())));
  116. }
  117. //////////////////////////////////////////////////////////////////////////////
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement