Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class CameraActivity extends AppCompatActivity implements OnImageAvailableListener, Camera.PreviewCallback, CompoundButton.OnCheckedChangeListener, View.OnClickListener {
- //////////////////////////////////////////////////////////////////////////////
- String address = null , name=null;
- BluetoothAdapter myBluetooth = null;
- BluetoothSocket btSocket = null;
- Set<BluetoothDevice> pairedDevices;
- static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
- //////////////////////////////////////////////////////////////////////////////
- private static final Logger LOGGER = new Logger();
- private static final int PERMISSIONS_REQUEST = 1;
- private static final String PERMISSION_CAMERA = Manifest.permission.CAMERA;
- ...
- @Override
- protected void onCreate(final Bundle savedInstanceState) {
- LOGGER.d("onCreate " + this);
- super.onCreate(null);
- //////////////////////////////////////////////////////////////////////////////
- try {setw();} catch (Exception e) {}
- //////////////////////////////////////////////////////////////////////////////
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- setContentView(R.layout.activity_camera);
- Toolbar toolbar = findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayShowTitleEnabled(false);
- if (hasPermission()) {
- setFragment();
- } else {
- requestPermission();
- }
- ...
- ...
- }
- //////////////////////////////////////////////////////////////////////////////
- @SuppressLint("ClickableViewAccessibility")
- private void setw() throws IOException {
- bluetooth_connect_device();
- }
- private void bluetooth_connect_device() throws IOException
- {
- try
- {
- myBluetooth = BluetoothAdapter.getDefaultAdapter();
- address = myBluetooth.getAddress();
- pairedDevices = myBluetooth.getBondedDevices();
- if (pairedDevices.size()>0)
- {
- for(BluetoothDevice bt : pairedDevices)
- {
- address=bt.getAddress().toString();name = bt.getName().toString();
- Toast.makeText(getApplicationContext(),"Connected", Toast.LENGTH_SHORT).show();
- }
- }
- }
- catch(Exception we){}
- myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
- BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
- btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
- btSocket.connect();
- try {}
- catch(Exception e){}
- }
- public void write(String s) throws IOException {
- btSocket.getOutputStream().write(s.getBytes());
- }
- //////////////////////////////////////////////////////////////////////////////
- public synchronized void draw(final Canvas canvas) throws IOException, InterruptedException {
- final boolean rotated = sensorOrientation % 180 == 90;
- final float multiplier =
- Math.min(
- canvas.getHeight() / (float) (rotated ? frameWidth : frameHeight),
- canvas.getWidth() / (float) (rotated ? frameHeight : frameWidth));
- frameToCanvasMatrix =
- ImageUtils.getTransformationMatrix(
- frameWidth,
- frameHeight,
- (int) (multiplier * (rotated ? frameHeight : frameWidth)),
- (int) (multiplier * (rotated ? frameWidth : frameHeight)),
- sensorOrientation,
- false);
- for (final TrackedRecognition recognition : trackedObjects) {
- final RectF trackedPos = new RectF(recognition.location);
- getFrameToCanvasMatrix().mapRect(trackedPos);
- boxPaint.setColor(recognition.color);
- float cornerSize = Math.min(trackedPos.width(), trackedPos.height()) / 8.0f;
- canvas.drawRoundRect(trackedPos, cornerSize, cornerSize, boxPaint);
- final String labelString =
- !TextUtils.isEmpty(recognition.title)
- ? String.format("%s %.0f %.0f %.2f", recognition.title, trackedPos.centerX(), trackedPos.centerY(), (100 * recognition.detectionConfidence))
- : String.format("%.2f", (100 * recognition.detectionConfidence));
- borderedText.drawText(
- canvas, trackedPos.left + cornerSize, trackedPos.top, labelString + '%' , boxPaint);
- //////////////////////////////////////////////////////////////////////////////
- if(recognition.title == "person" && (100 * recognition.detectionConfidence) > 40)
- {
- cameraActivity.write(Integer.toString(Math.round(trackedPos.centerY())));
- }
- //////////////////////////////////////////////////////////////////////////////
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement