pinky is not in the sudoers file. This incident will be reported.
时间: 2023-11-16 09:49:11 浏览: 145
根据提供的引用内容,"pinky is not in the sudoers file. This incident will be reported." 是一条错误消息,通常是在Linux系统中使用sudo命令时出现的。这个错误消息意味着用户"Pinky"没有被授权执行sudo命令的权限。该错误消息将被记录并报告给系统管理员。
相关问题
MediaPipe检测握拳伸掌
### 使用MediaPipe进行手部动作检测
为了实现握拳和伸掌姿态的识别,可以利用MediaPipe Hands模块来获取手部的关键点位置。该方法能够精确提取21个3D手部骨骼关键点坐标[^1]。基于这些坐标数据,可以通过分析特定关节的角度变化来进行不同手势分类。
#### 关键步骤说明
- **初始化MediaPipe Hands**
需要先安装并导入必要的库文件,接着创建Hands对象实例用于处理视频流中的每一帧画面:
```python
import cv2
import mediapipe as mp
mp_hands = mp.solutions.hands.Hands(
static_image_mode=False,
max_num_hands=2, # 可根据需求调整最大检测数量
min_detection_confidence=0.75,
min_tracking_confidence=0.75)
```
- **捕获与预处理图像**
利用OpenCV读取摄像头或本地存储的视频源,并将其转换成RGB格式供后续操作使用:
```python
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = mp_hands.process(image_rgb)
```
- **计算角度特征**
对于每只被成功追踪到的手,可以根据指定的关键点ID(如指尖、指根等部位),计算相邻两节骨头之间的夹角作为区分不同姿势的重要依据之一。例如,在判断是否为握拳状态时,可重点考察五个手指尖端与其对应近侧指间关节处形成的弯曲程度;而当手掌完全展开时,则上述各角度应接近直线分布特性[^3]。
```python
def calculate_angle(a,b,c):
ba = a - b
bc = c - b
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba)*np.linalg.norm(bc))
angle = np.arccos(cosine_angle)
return round(np.degrees(angle),2)
if results.multi_hand_landmarks is not None:
for handLms in results.multi_hand_landmarks:
landmarks = []
for lm in handLms.landmark:
h,w,_ = frame.shape
cx,cy=int(lm.x*w),int(lm.y*h)
landmarks.append([cx,cy])
thumb_tip = np.array(landmarks[4]) # 大拇指顶端
index_mcp = np.array(landmarks[5]) # 食指MCP节点
pinky_mcp = np.array(landmarks[17]) # 小指MCP节点
wrist_pos = np.array(landmarks[0]) # 腕部中心
angles = [
calculate_angle(thumb_tip,index_mcp,pinky_mcp),
...
]
```
- **定义决策逻辑**
设定合理的阈值范围以判定当前所展示的具体手势类别。比如,如果所有五指均呈现较大曲率,则认为处于“握拳”模式下;反之若是大部分角度趋于平直,则视为执行了“张开手掌”的指令[^4]。
```python
threshold_fist = 90 # 握拳状态下预期的最大角度上限
is_fist = all(angle >= threshold_fist for angle in angles[:-1])
if is_fist:
print('Detected Fist')
else:
print('Palm Opened')
```
基于MediaPipe 手势识别
### 使用 MediaPipe 进行手势识别
#### 安装依赖包
为了实现手部追踪和手势识别,需先安装必要的 Python 包。这包括 `mediapipe` 和 `opencv-python`。
```bash
pip install mediapipe opencv-python
```
#### 初始化摄像头输入与MediaPipe Hands模块
创建一个简单的程序结构用于读取视频流并初始化 MediaPipe 的Hands解决方案[^1]。
```python
import cv2
import mediapipe as mp
mp_hands = mp.solutions.hands
hands = mp_hands.Hands()
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# 将BGR图像转换为RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(rgb_frame)
# 处理检测结果...
cv2.imshow('Hand Tracking', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
```
#### 解析手部关键点数据
当成功获取到手部的关键点后,可以通过遍历 landmarks 属性访问这些坐标位置,并绘制出来以便观察[^2]。
```python
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
for id, lm in enumerate(handLms.landmark):
h, w, c = frame.shape
cx, cy = int(lm.x *w), int(lm.y*h)
print(id, cx, cy)
mp_drawing.draw_landmarks(
frame,
handLms,
mp_hands.HAND_CONNECTIONS
)
```
#### 实现基本的手势判断逻辑
根据特定条件定义简单手势(如握拳、张开手掌),通过比较某些关键点之间的相对距离来进行判定[^3]。
```python
def is_fist_closed(landmarks):
thumb_tip_y = landmarks[4].y
index_finger_mcp_y = landmarks[5].y
pinky_mcp_y = landmarks[17].y
return all([
thumb_tip_y > index_finger_mcp_y,
thumb_tip_y > pinky_mcp_y
])
# 在主循环内调用此函数以检查当前帧中的手势状态
if results.multi_hand_landmarks:
handLandmarks = results.multi_hand_landmarks[0]
landmark_list = []
for point in handLandmarks.landmark:
landmark_list.append(point)
gesture_name = "FIST CLOSED" if is_fist_closed(landmark_list) else "HAND OPEN"
cv2.putText(frame, str(gesture_name), (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2, cv2.LINE_AA)
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)