// Copyright 2021 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.catand.armtorobot;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.exifinterface.media.ExifInterface;
import com.catand.armtorobot.commen.Constants;
import com.catand.armtorobot.connect.BLEManager;
import com.catand.armtorobot.connect.BLEService;
import com.catand.armtorobot.model.ByteCommand;
import com.catand.armtorobot.model.ServoAction;
import com.catand.armtorobot.uitls.BluetoothUtils;
import com.catand.armtorobot.uitls.CmdUtil;
import com.catand.armtorobot.uitls.LandmarkUtil;
import com.catand.armtorobot.uitls.LogUtil;
import com.catand.armtorobot.uitls.PermissionHelperBluetooth;
import com.catand.armtorobot.widget.NetworkDialog;
import com.catand.armtorobot.widget.PromptDialog;
import com.catand.armtorobot.widget.SearchDialog;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.mediapipe.formats.proto.LandmarkProto;
import com.google.mediapipe.solutioncore.CameraInput;
import com.google.mediapipe.solutioncore.SolutionGlSurfaceView;
import com.google.mediapipe.solutions.hands.HandLandmark;
import com.google.mediapipe.solutions.hands.Hands;
import com.google.mediapipe.solutions.hands.HandsOptions;
import com.google.mediapipe.solutions.hands.HandsResult;
import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
/**
* 应用程序的主Activity.
*/
public class MainActivity extends AppCompatActivity implements SearchDialog.OnDeviceSelectedListener, NetworkDialog.OnRobotSelectedListener {
private FirebaseAnalytics mFirebaseAnalytics;
private static final String TAG = MainActivity.class.getSimpleName();
private Hands hands;
private final int HANDS_NUM = 1;
//在 GPU 或 CPU 上运行管道和模型推理.
private static final boolean RUN_ON_GPU = true;
private enum InputSource {
UNKNOWN,
IMAGE,
CAMERA,
}
private InputSource inputSource = InputSource.UNKNOWN;
// 图像演示 UI 和图像加载器组件.
private ActivityResultLauncher<Intent> imageGetter;
private HandsResultImageView imageView;
// 实时摄像头演示 UI 和摄像头组件.
private CameraInput cameraInput;
private SolutionGlSurfaceView<HandsResult> glSurfaceView;
//蓝牙重试次数
private static final int RETRY_TIMES = 3;
//确认退出
private boolean confirm;
//蓝牙按钮图像
private ImageButton btStateBtn;
//蓝牙适配器
public static BluetoothAdapter mBluetoothAdapter = null;
public static BLEManager bleManager;
public static BluetoothDevice mBluetoothDevice;
private Handler mHandler;
/**
* 已尝试连接次数
*/
private int connectTimes;
/**
* 蓝牙连接状态
*/
public static boolean bluetoothIsConnected;
/**
* 服务器连接状态
*/
public static boolean networkIsConnected;
//通用方法
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化 Firebase
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
//初始化按钮点击事件监听器
setupStaticImageDemoUiComponents();
setupLiveDemoUiComponents();
setupBluetoothClick();
setupSetClick();
setupTestClick();
setupNetworkClick();
if (!BluetoothUtils.isSupport(BluetoothAdapter.getDefaultAdapter())) {
Toast.makeText(this, "蓝牙不可用", Toast.LENGTH_LONG).show();
finish();
}
//创建蓝牙按钮对象
btStateBtn = findViewById(R.id.bluetooth_btn);
Intent intent = new Intent(this, BLEService.class);
startService(intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
BLEManager.getInstance().register(this);
mHandler = new Handler(new MsgCallBack());
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//重置连接尝试次数
connectTimes = 0;
}
//当应用恢复前台运行
@Override
protected void onResume() {
super.onResume();
//相机
//如果目前工作源是摄像头,就重启相机和opengl表面渲染
if (inputSource == InputSource.CAMERA) {
cameraInput = new CameraInput(this);
cameraInput.setNewFrameListener(textureFrame -> hands.send(textureFrame));
glSurfaceView.post(this::startCamera);
glSurfaceView.setVisibility(View.VISIBLE);
}
//蓝牙
bleManager = BLEManager.getInstance();
bluetoothIsConnected = bleManager.isConnected();
bleManager.setHandler(mHandler);
LogUtil.i(TAG, "onResume isConnected= " + bluetoothIsConnected);
setState(bluetoothIsConnected);
}
//当应用进入后台
@Override
protected void onPause() {
super.onPause();
//如果目前工作源是摄像头,就完全隐藏输出界面并关闭视频流
if (inputSource == InputSource.CAMERA) {
glSurfaceView.setVisibility(View.GONE);
cameraInput.close();
}
}
//当Activity被销毁
@Override
protected void onDestroy() {
LogUtil.i(TAG, "onCreate");
unbindService(mConnection);
BLEManager.getInstance().unregister(this);
super.onDestroy();
}
//当返回键被按下
@Override
public void onBackPressed() {
if (BLEManager.getInstance().isConnected()) {
PromptDialog.create(this, getFragmentManager(), getString(R.string.exit_tips_title),
getString(R.string.exit_tips_content), (dialog, which) -> {
if (DialogInterface.BUTTON_POSITIVE == which) {
BLEManager.getInstance().stop();
MainActivity.super.onBackPressed();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
} else {
if (!confirm) {
confirm = true;
Toast.makeText(this, R.string.exit_remind, Toast.LENGTH_SHORT).show();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
confirm = false;
}
}, 2000);
} else {
Intent intent = new Intent(this, BLEService.class);
stopService(intent);
BLEManager.getInstance().destroy();
super.onBackPressed();
android.os.Process.killProcess(android.os.Process.myPid());
}
}
}
//mediapipe方法
//把原Bitmap等比例无裁剪缩小到适合imageView的大小
private Bitmap downscaleBitmap(Bitmap originalBitmap) {
//纵横比
double aspectRatio = (double) originalBitmap.getWidth() / originalBitmap.getHeight();
int width = imageView.getWidth();
int height = imageView.getHeight();
if (((double) imageView.getWidth() / imageView.getHeight()) > aspectRatio) {
width =
没有合适的资源?快使用搜索试试~ 我知道了~
手部识别操控机械臂+源代码+文档说明
共75个文件
xml:34个
java:20个
png:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 52 浏览量
2024-08-13
21:26:34
上传
评论
收藏 191KB ZIP 举报
温馨提示
<项目介绍> - 手部识别操控机械臂 - 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
资源推荐
资源详情
资源评论
收起资源包目录
手部识别操控机械臂.zip (75个子文件)
ArmToRobot-master
gradle.properties 1KB
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 200B
.gitattributes 66B
gradlew.bat 3KB
build.gradle 716B
settings.gradle 60B
gradlew 6KB
.gitignore 382B
hands
src
main
java
com
catand
armtorobot
connect
BLEService.java 11KB
BLEManager.java 12KB
commen
Constants.java 2KB
HandsResultImageView.java 5KB
model
ServoAction.java 797B
ByteCommand.java 1KB
uitls
PermissionHelperBluetooth.java 4KB
LogUtil.java 2KB
TimerLog.java 371B
CmdUtil.java 5KB
ColorUtil.java 3KB
LandmarkUtil.java 3KB
BluetoothUtils.java 2KB
MainActivity.java 23KB
HandsResultGlRenderer.java 7KB
widget
NetworkDialog.java 7KB
CircularProgressView.java 11KB
BaseDialog.java 3KB
PromptDialog.java 2KB
SearchDialog.java 7KB
res
anim
ic_bluetooth_transient_animation_1.xml 3KB
ic_bluetooth_transient_animation_0.xml 3KB
ic_bluetooth_transient_animation_2.xml 1003B
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 8KB
mipmap-hdpi
ic_launcher_round.png 4KB
ic_launcher.png 3KB
mipmap-mdpi
ic_launcher_round.png 2KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 14KB
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher_round.png 6KB
ic_launcher.png 5KB
values
colors.xml 1KB
attr.xml 2KB
strings.xml 2KB
styles.xml 536B
layout
layout_dialog.xml 3KB
layout_dialog_prompot.xml 2KB
activity_main.xml 3KB
network_dialog.xml 4KB
item_search_device.xml 720B
drawable
stat_notify_wifi_in_range_bg.xml 1024B
stat_notify_wifi_in_range_front.xml 1024B
ic_bluetooth_transient_animation_drawable_blue.xml 975B
ic_bluetooth_transient_animation_drawable_red.xml 2KB
ic_qs_dnd_bg.xml 427B
ic_settings_24dp.xml 277B
stat_notify_wifi_in_range.xml 295B
ic_settings_24dp_front.xml 2KB
ic_refresh_front.xml 712B
ic_wifi_signal_0.xml 466B
ic_refresh.xml 265B
ic_bluetooth_transient_animation_red.xml 584B
ic_qs_dnd.xml 263B
ic_refresh_bg.xml 712B
ic_settings_24dp_bg.xml 2KB
ic_wifi_signal_4.xml 383B
ic_wifi_signal_2.xml 693B
ic_wifi_signal_1.xml 706B
ic_wifi_signal_3.xml 688B
ic_dialog_alert_material.xml 397B
ic_qs_dnd_front.xml 427B
AndroidManifest.xml 2KB
proguard-rules.pro 751B
build.gradle 2KB
共 75 条
- 1
资源评论
程序员无锋
- 粉丝: 3683
- 资源: 2320
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- base(1).apk.1
- K618977005_2012-12-6_beforeP_000.txt.PRM
- 秋招信息获取与处理基础教程
- 程序员面试笔试面经技巧基础教程
- Python实例-21个自动办公源码-数据处理技术+Excel+自动化脚本+资源管理
- 全球前8GDP数据图(python动态柱状图)
- 汽车检测7-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- 检测高压线电线-YOLO(v5至v9)、COCO、Darknet、VOC数据集合集.rar
- 检测行路中的人脸-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、VOC数据集合集.rar
- Image_17083039753012.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功