本帖最后由 云天 于 2021-5-23 11:16 编辑
【查看Python版本】
- <div class="blockcode"></div>
复制代码
进入 python3 测试,结果报错,缺少依赖库,按照提示安装依赖库:
- pi@raspberrypi:~ $ python
- Python 3.7.3 (default, Jul 25 2020, 13:03:44)
- [GCC 8.3.0] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import cv2
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "/home/pi/.local/lib/python3.7/site-packages/cv2/__init__.py", line 5, in <module>
- from .cv2 import *
- ImportError: libcblas.so.3: cannot open shared object file: No such file or directory
复制代码
安装:
- sudo apt-get install libatlas-base-dev
复制代码
OpenCV(Open Source Computer Vision Library) 是一个基于BSD许可(开源)发行的跨平台计算机视觉库,它具有C ++,C,Python和Java接口,可以运行在Linux、Windows、Mac OS和Android操作系统上。OpenCV的设计是为了提高计算效率,并将重点放在实时应用程序上, 用优化的C / C ++编写,库可以利用多核处理,实现了图像处理和计算机视觉方面的很多通用算法。
【测试OpenCV】
-
- import cv2
-
- cap = cv2.VideoCapture(0)
-
- while(1):
- # 获得图片
- ret, frame = cap.read()
- # 展示图片
- cv2.imshow("capture", frame)
- if cv2.waitKey(30) & 0xFF == ord('q'):
- # 存储图片
- cv2.imwrite("camera.jpg", frame)
- break
-
- cap.release()
- cv2.destroyAllWindows()
-
复制代码
因开启摄像头后,发现CM4发热严重,在上面放置了一个树莓派专用风扇进行散热。
【人脸识别】
- import cv2
- import sys
- if __name__ == '__main__':
- cascPath = "./haarcascade_frontalface_alt2.xml"
- faceCascade = cv2.CascadeClassifier(cascPath)
- cap = cv2.VideoCapture(0)
-
- while cap.isOpened():
- ret, frame = cap.read()
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- faces = faceCascade.detectMultiScale(
- gray,
- scaleFactor=1.1,
- minNeighbors=3,
- minSize=(30, 30),
- flags=cv2.ORB_HARRIS_SCORE
- )
- for (x, y, w, h) in faces:
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- if ret == True:
- cv2.namedWindow("frame",0);
- cv2.resizeWindow("frame", 80, 60);
- cv2.imshow('frame', frame);
- if cv2.waitKey(1) & 0xff == ord('q'):
- break
- cap.release()
-
- cv2.destroyAllWindows()
复制代码
|