cv2.FILLED
时间: 2024-04-10 20:25:28 浏览: 37
cv2.FILLED是Python编程语言中,使用OpenCV库的一个参数。它用于指定在绘制形状或轮廓时使用的填充颜色。
具体来说,cv2.FILLED是OpenCV库中cv2.arcTo()函数的填充参数。这个参数决定了在绘制弧线段时是否应该填充颜色。如果cv2.FILLED设置为True,那么弧线段将被填充颜色;如果设置为False,那么弧线段将不会被填充颜色。
cv2.arcTo()函数用于将一个弧线段转换为一条线段,而cv2.FILLED参数可以控制线条的外观。这对于在图像处理和计算机视觉任务中创建特定的视觉效果非常有用。
需要注意的是,cv2.FILLED参数的具体颜色取决于OpenCV库中设置的背景颜色和前景颜色。通常,黑色或白色背景上的填充颜色可以是任何颜色。
在使用OpenCV库时,可以通过设置cv2.FILLED参数来控制线条和形状的外观,以达到所需的效果。
相关问题
import cv2 import mediapipe as mp import time cap = cv2.VideoCapture(0) mpHands = mp.solutions.hands hands = mpHands.Hands() mpDraw = mp.solutions.drawing_utils pTime = 0 cTime = 0 while True: success, img = cap.read() imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) results = hands.process(imgRGB) #print(results.multi_hand_landmarks) if results.multi_hand_landmarks: for handLms in results.multi_hand_landmarks: for id, lm in enumerate(handLms.landmark): #print(id,lm) h, w, c = img.shape cx, cy = int(lm.x *w), int(lm.y*h) #if id ==0: cv2.circle(img, (cx,cy), 7, (255,0,255), cv2.FILLED) mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS) cTime = time.time() fps = 1/(cTime-pTime) pTime = cTime cv2.putText(img,str(int(fps)), (10,70), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,255), 3) cv2.imshow("Image", img) cv2.waitKey(1)
这段代码使用OpenCV和MediaPipe库实现了手部姿势检测,并在视频流中绘制了手部关键点和连接线。具体实现如下:
1. 导入必要的库和模块:
```
import cv2
import mediapipe as mp
import time
```
2. 初始化摄像头并创建MediaPipe Hands模型:
```
cap = cv2.VideoCapture(0) # 初始化摄像头
mpHands = mp.solutions.hands # 创建MediaPipe Hands模型
hands = mpHands.Hands() # 实例化模型
mpDraw = mp.solutions.drawing_utils # 创建绘图工具
```
3. 循环读取视频帧并进行手部姿势检测:
```
while True:
success, img = cap.read() # 读取视频帧
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 将BGR图像转换为RGB图像
results = hands.process(imgRGB) # 进行手部姿势检测
```
4. 绘制手部关键点和连接线:
```
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
for id, lm in enumerate(handLms.landmark):
h, w, c = img.shape
cx, cy = int(lm.x *w), int(lm.y*h)
cv2.circle(img, (cx,cy), 7, (255,0,255), cv2.FILLED)
mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
```
5. 计算并显示帧率:
```
cTime = time.time()
fps = 1/(cTime-pTime)
pTime = cTime
cv2.putText(img,str(int(fps)), (10,70), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,255), 3)
```
6. 显示处理后的帧:
```
cv2.imshow("Image", img)
cv2.waitKey(1)
```
mask_box = np.zeros_like(mask_k) mask_box = cv2.drawContours( mask_box, [box.astype(int)], 0, 255, cv2.FILLED) mask_c = np.logical_and(mask_box == 255, mask_k == 255)
这段代码的作用是利用旋转bounding box来对二值掩膜进行裁剪,具体来说,它执行了以下几个步骤:
1.创建一个和原始掩膜大小相同的全零数组mask_box;
2.使用cv2.drawContours函数将旋转bounding box绘制在mask_box上,并将其内部填充为白色(像素值为255);
3.通过逻辑运算,将mask_box和原始掩膜mask_k中值均为255的像素提取出来,存储在mask_c中。
其中,np.zeros_like函数用于创建一个和原始掩膜大小相同、所有元素值都为0的数组。cv2.drawContours函数用于在给定图像上绘制轮廓,其中第一个参数为目标图像、第二个参数为轮廓、第三个参数为轮廓的索引(-1表示绘制所有轮廓)、第四个参数为颜色、第五个参数为线条宽度。需要注意的是,该函数也是基于OpenCV的cv2模块。逻辑运算np.logical_and用于对数组进行逐元素的与运算。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)