Skip to content

Commit db8c2c4

Browse files
committed
增加pymycobot版本提示信息、增加hsv颜色检测脚本
1 parent 72c244c commit db8c2c4

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

hsv_color_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/python
2+
# -*- coding:utf-8 -*-
3+
# @File : hsv_color_test.py
4+
# @Author : Wang Weijian
5+
# @Time : 2024/12/16 10:14:57
6+
# @function: the script is used to do something
7+
# @version : V1
8+
import cv2
9+
import platform
10+
11+
import numpy as np
12+
13+
if platform.system() == "Windows":
14+
cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
15+
elif platform.system() == "Linux":
16+
cap = cv2.VideoCapture(0, cv2.CAP_V4L)
17+
18+
for i in range(0, 19):
19+
print(cap.get(i))
20+
21+
HSV = {
22+
"yellow": [np.array([11, 85, 70]), np.array([59, 255, 245])],
23+
"red": [np.array([0, 43, 46]), np.array([8, 255, 255])],
24+
"green": [np.array([35, 43, 35]), np.array([90, 255, 255])],
25+
"blue": [np.array([78, 43, 46]), np.array([110, 255, 255])],
26+
"cyan": [np.array([78, 43, 46]), np.array([99, 255, 255])],
27+
}
28+
29+
while 1:
30+
31+
ret, frame = cap.read()
32+
33+
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
34+
35+
lower_red = np.array([0, 43, 46])
36+
37+
upper_red = np.array([8, 255, 255])
38+
39+
mask = cv2.inRange(hsv, lower_red, upper_red) # 红色掩模
40+
41+
res = cv2.bitwise_and(frame, frame, mask=mask)
42+
43+
cv2.imshow(u"Capture", frame)
44+
45+
cv2.imshow(u"mask", mask)
46+
47+
cv2.imshow(u"res", res)
48+
49+
key = cv2.waitKey(1)
50+
51+
if key & 0xff == ord('q') or key == 27:
52+
print(frame.shape, ret)
53+
54+
break
55+
56+
cap.release()
57+
58+
cv2.destroyAllWindows()

main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,24 @@
1717
from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication
1818
from PyQt5.QtGui import QEnterEvent, QPixmap
1919
from PyQt5.QtWidgets import QMainWindow, QApplication, QInputDialog, QWidget, QMessageBox, QPushButton, QComboBox
20-
# from pymycobot.mycobot import MyCobot
21-
from pymycobot.mycobot320 import MyCobot320
2220
from PyQt5.QtCore import QTimer
2321
from libraries.log import logfile
2422
from libraries.pyqtFile.AiKit_auto import Ui_AiKit_UI as AiKit_window
23+
import pymycobot
24+
from packaging import version
25+
26+
# min low version require
27+
MIN_REQUIRE_VERSION = '3.6.8'
28+
29+
current_verison = pymycobot.__version__
30+
print('current pymycobot library version: {}'.format(current_verison))
31+
if version.parse(current_verison) < version.parse(MIN_REQUIRE_VERSION):
32+
raise RuntimeError(
33+
'The version of pymycobot library must be greater than {} or higher. The current version is {}. Please upgrade the library version.'.format(
34+
MIN_REQUIRE_VERSION, current_verison))
35+
else:
36+
print('pymycobot library version meets the requirements!')
37+
from pymycobot.mycobot320 import MyCobot320
2538

2639

2740
class AiKit_APP(AiKit_window, QMainWindow, QWidget):

0 commit comments

Comments
 (0)