日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenCV AprilTags 识别

發布時間:2025/5/22 编程问答 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV AprilTags 识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用環境:

  • Windows10
  • Raspberry Pi 4B
  • Python :3.7.3

Windows下使用 AprilTags

在windows中安裝 apriltags 庫:

pip install pupil-apriltags

代碼部分:

import pupil_apriltags as apriltag # 在 windows 下引入該庫 import cv2img = cv2.imread('1.jpg', cv2.IMREAD_GRAYSCALE) detector = apriltag.Detector() result = detector.detect(img) print(result)


識別后得到的信息:

通過檢測到的參數,標記四個角點。

#!/usr/bin/env python # coding: UTF-8 import pupil_apriltags as apriltag import cv2img = cv2.imread("tag36h11_0.png") gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# 創建一個apriltag檢測器 detector = apriltag.Detector(families='tag36h11') # windows# 進行apriltag檢測,得到檢測到的apriltag的列表 tags = detector.detect(gray)for tag in tags:cv2.circle(img, tuple(tag.corners[0].astype(int)), 4, (255, 0, 255), 2) # left-topcv2.circle(img, tuple(tag.corners[1].astype(int)), 4, (255, 0, 255), 2) # right-topcv2.circle(img, tuple(tag.corners[2].astype(int)), 4, (255, 0, 255), 2) # right-bottomcv2.circle(img, tuple(tag.corners[3].astype(int)), 4, (255, 0, 255), 2) # left-bottomcv2.imshow("out_image", img) cv2.imwrite('image.png', img) cv2.waitKey()

使用line繪制邊框

import cv2 import pupil_apriltags as apriltag # windowsimage = cv2.imread('tag36h11_0.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 創建一個apriltag檢測器,然后檢測AprilTags options = apriltag.Detector(families='tag36h11') # windows results = options.detect(gray) print(results)for r in results:# 獲取4個角點的坐標b = (tuple(r.corners[0].astype(int))[0], tuple(r.corners[0].astype(int))[1])c = (tuple(r.corners[1].astype(int))[0], tuple(r.corners[1].astype(int))[1])d = (tuple(r.corners[2].astype(int))[0], tuple(r.corners[2].astype(int))[1])a = (tuple(r.corners[3].astype(int))[0], tuple(r.corners[3].astype(int))[1])# 繪制檢測到的AprilTag的框cv2.line(image, a, b, (255, 0, 255), 2, lineType=cv2.LINE_AA)cv2.line(image, b, c, (255, 0, 255), 2, lineType=cv2.LINE_AA)cv2.line(image, c, d, (255, 0, 255), 2, lineType=cv2.LINE_AA)cv2.line(image, d, a, (255, 0, 255), 2, lineType=cv2.LINE_AA)# 繪制 AprilTag 的中心坐標(cX, cY) = (int(r.center[0]), int(r.center[1]))cv2.circle(image, (cX, cY), 5, (0, 0, 255), -1)# 在圖像上繪制標文本tagFamily = r.tag_family.decode("utf-8")cv2.putText(image, tagFamily, (a[0], a[1] - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)cv2.imwrite('image1.png', image)cv2.imshow("Image", image) cv2.waitKey(0)

樹莓派4B下使用 AprilTags

在樹莓派下安裝 AprilTags

pip3 install apriltag

pi@raspberrypi:~ $ pip3 install apriltag
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting apriltag
Downloading https://www.piwheels.org/simple/apriltag/apriltag-0.0.16-cp37-cp37m-linux_armv7l.whl (433kB)
100% |████████████████████████████████| 440kB 212kB/s
Installing collected packages: apriltag
Successfully installed apriltag-0.0.16

打開樹莓派4B攝像頭進行檢測

#!/usr/bin/env python # coding: UTF-8 import apriltag import cv2cap = cv2.VideoCapture(0) at_detector = apriltag.Detector(apriltag.DetectorOptions(families='tag36h11'))while(1):# 獲得圖像ret, frame = cap.read()# 檢測按鍵k = cv2.waitKey(1)if k==27:break# 檢測apriltaggray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)tags = at_detector.detect(gray)for tag in tags:cv2.circle(frame, tuple(tag.corners[0].astype(int)), 4, (255, 0, 0), 2) # left-topcv2.circle(frame, tuple(tag.corners[1].astype(int)), 4, (255, 0, 0), 2) # right-topcv2.circle(frame, tuple(tag.corners[2].astype(int)), 4, (255, 0, 0), 2) # right-bottomcv2.circle(frame, tuple(tag.corners[3].astype(int)), 4, (255, 0, 0), 2) # left-bottom# 顯示檢測結果cv2.imshow('capture', frame)cap.release() cv2.destroyAllWindows()

打開樹莓派4B攝像頭進行檢測使用類進行封裝

import cv2 import apriltagclass ApriltagDetect:def __init__(self):self.target_id = 0self.at_detector = apriltag.Detector(apriltag.DetectorOptions(families='tag36h11'))def update_frame(self,frame):gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)tags = self.at_detector.detect(gray)for tag in tags:print(tag.tag_id)cv2.circle(frame, tuple(tag.corners[0].astype(int)), 4, (0, 0, 255), 2) # left-topcv2.circle(frame, tuple(tag.corners[1].astype(int)), 4, (0, 0, 255), 2) # right-topcv2.circle(frame, tuple(tag.corners[2].astype(int)), 4, (0, 0, 255), 2) # right-bottomcv2.circle(frame, tuple(tag.corners[3].astype(int)), 4, (0, 0, 255), 2) # left-bottomapriltag_width = abs(tag.corners[0][0] - tag.corners[1][0]) / 2target_x = apriltag_width / 2if __name__ == '__main__':cap = cv2.VideoCapture(0)cap.set(3,640)cap.set(4,480)ad = ApriltagDetect()while True:ret, frame = cap.read()frame = cv2.rotate(frame, cv2.ROTATE_180)ad.update_frame(frame)cv2.imshow("capture", frame)if cv2.waitKey(100) & 0xff == ord('q'):breakcap.release()cv2.destroyAllWindows()

踩坑:

安裝 opencv-python 庫后,無法引用cv2:

pi@raspberrypi:~/Desktop $ python3
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 “”, line 1, in
File “/home/pi/.local/lib/python3.7/site-packages/cv2/init.py”, line 3, in
from .cv2 import *
ImportError: libhdf5_serial.so.103: cannot open shared object file: No such file or directory

解決方法:

在樹莓派下安裝 opencv-python 庫

pip3 install opencv-python

pi@raspberrypi:~/Desktop $ pip3 install opencv-python
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-python
Downloading https://www.piwheels.org/simple/opencv-python/opencv_python-4.5.3.56-cp37-cp37m-linux_armv7l.whl (10.4MB)
100% |████████████████████████████████| 10.4MB 41kB/s
Requirement already satisfied: numpy>=1.14.5 in /usr/lib/python3/dist-packages (from opencv-python) (1.16.2)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.3.56

安裝 opencv-contrib-python庫

pi@raspberrypi:~/Desktop $ pip3 install opencv-contrib-python==4.1.0.25
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-contrib-python==4.1.0.25
Downloading https://www.piwheels.org/simple/opencv-contrib-python/opencv_contrib_python-4.1.0.25-cp37-cp37m-linux_armv7l.whl (15.7MB)
100% |████████████████████████████████| 15.7MB 27kB/s
Requirement already satisfied: numpy>=1.16.2 in /usr/lib/python3/dist-packages (from opencv-contrib-python==4.1.0.25) (1.16.2)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.1.0.25

安裝 libatlas-base-dev

pi@raspberrypi:~/Desktop $ sudo apt-get install libatlas-base-dev -y
正在讀取軟件包列表… 完成
正在分析軟件包的依賴關系樹
正在讀取狀態信息… 完成
將會同時安裝下列軟件:
libatlas3-base
建議安裝:
libatlas-doc liblapack-doc
下列【新】軟件包將被安裝:
libatlas-base-dev libatlas3-base
升級了 0 個軟件包,新安裝了 2 個軟件包,要卸載 0 個軟件包,有 151 個軟件包未被升級。
需要下載 5,365 kB 的歸檔。
解壓縮后會消耗 32.1 MB 的額外空間。
獲取:1 http://mirrors.sjtug.sjtu.edu.cn/raspbian/raspbian buster/main armhf libatlas3-base armhf 3.10.3-8+rpi1 [2,399 kB]
獲取:2 http://mirrors.sjtug.sjtu.edu.cn/raspbian/raspbian buster/main armhf libatlas-base-dev armhf 3.10.3-8+rpi1 [2,966 kB]
已下載 5,365 kB,耗時 10秒 (555 kB/s)
正在選中未選擇的軟件包 libatlas3-base:armhf。
(正在讀取數據庫 … 系統當前共安裝有 180903 個文件和目錄。)
準備解壓 …/libatlas3-base_3.10.3-8+rpi1_armhf.deb …
正在解壓 libatlas3-base:armhf (3.10.3-8+rpi1) …
正在選中未選擇的軟件包 libatlas-base-dev:armhf。
準備解壓 …/libatlas-base-dev_3.10.3-8+rpi1_armhf.deb …
正在解壓 libatlas-base-dev:armhf (3.10.3-8+rpi1) …
正在設置 libatlas3-base:armhf (3.10.3-8+rpi1) …
update-alternatives: 使用 /usr/lib/arm-linux-gnueabihf/atlas/libblas.so.3 來在自動模式中提供 /usr/lib/arm-linux-gnueabihf/libblas.so.3 (libblas.so.3-arm-linux-gnueabihf)
update-alternatives: 使用 /usr/lib/arm-linux-gnueabihf/atlas/liblapack.so.3 來在自動模式中提供 /usr/lib/arm-linux-gnueabihf/liblapack.so.3 (liblapack.so.3-arm-linux-gnueabihf)
正在設置 libatlas-base-dev:armhf (3.10.3-8+rpi1) …
update-alternatives: 使用 /usr/lib/arm-linux-gnueabihf/atlas/libblas.so 來在自動模式中提供 /usr/lib/arm-linux-gnueabihf/libblas.so (libblas.so-arm-linux-gnueabihf)
update-alternatives: 使用 /usr/lib/arm-linux-gnueabihf/atlas/liblapack.so 來在自動模式中提供 /usr/lib/arm-linux-gnueabihf/liblapack.so (liblapack.so-arm-linux-gnueabihf)
正在處理用于 libc-bin (2.28-10+rpi1) 的觸發器 …

安裝 libjasper-dev

pi@raspberrypi:~/Desktop $ sudo apt-get install libjasper-dev -y
正在讀取軟件包列表… 完成
正在分析軟件包的依賴關系樹
正在讀取狀態信息… 完成
將會同時安裝下列軟件:
libjasper1
建議安裝:
libjasper-runtime
下列【新】軟件包將被安裝:
libjasper-dev libjasper1
升級了 0 個軟件包,新安裝了 2 個軟件包,要卸載 0 個軟件包,有 151 個軟件包未被升級。
需要下載 611 kB 的歸檔。
解壓縮后會消耗 1,207 kB 的額外空間。
獲取:1 http://mirrors.sjtug.sjtu.edu.cn/raspbian/raspbian buster/main armhf libjasper1 armhf 1.900.1-debian1-2.4+deb8u1 [110 kB]
獲取:2 http://mirrors.bfsu.edu.cn/raspbian/raspbian buster/main armhf libjasper-dev armhf 1.900.1-debian1-2.4+deb8u1 [501 kB]
已下載 611 kB,耗時 3秒 (232 kB/s)
正在選中未選擇的軟件包 libjasper1:armhf。
(正在讀取數據庫 … 系統當前共安裝有 181101 個文件和目錄。)
準備解壓 …/libjasper1_1.900.1-debian1-2.4+deb8u1_armhf.deb …
正在解壓 libjasper1:armhf (1.900.1-debian1-2.4+deb8u1) …
正在選中未選擇的軟件包 libjasper-dev。
準備解壓 …/libjasper-dev_1.900.1-debian1-2.4+deb8u1_armhf.deb …
正在解壓 libjasper-dev (1.900.1-debian1-2.4+deb8u1) …
正在設置 libjasper1:armhf (1.900.1-debian1-2.4+deb8u1) …
正在設置 libjasper-dev (1.900.1-debian1-2.4+deb8u1) …

安裝 libqtgui4

pi@raspberrypi:~/Desktop $ sudo apt-get install libqtgui4 -y

安裝 python3-pyqt5

sudo apt-get install python3-pyqt5 -y

安裝 libqt4-test

pi@raspberrypi:~/Desktop $ sudo apt-get install libqt4-test -y
正在讀取軟件包列表… 完成
正在分析軟件包的依賴關系樹
正在讀取狀態信息… 完成
下列【新】軟件包將被安裝:
libqt4-test
升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 0 個軟件包,有 151 個軟件包未被升級。
需要下載 98.0 kB 的歸檔。
解壓縮后會消耗 250 kB 的額外空間。
獲取:1 http://mirrors.bfsu.edu.cn/raspbian/raspbian buster/main armhf libqt4-test armhf 4:4.8.7+dfsg-18+rpi1+deb10u1 [98.0 kB]
已下載 98.0 kB,耗時 1秒 (71.5 kB/s)
正在選中未選擇的軟件包 libqt4-test:armhf。
(正在讀取數據庫 … 系統當前共安裝有 181337 個文件和目錄。)
準備解壓 …/libqt4-test_4%3a4.8.7+dfsg-18+rpi1+deb10u1_armhf.deb …
正在解壓 libqt4-test:armhf (4:4.8.7+dfsg-18+rpi1+deb10u1) …
正在設置 libqt4-test:armhf (4:4.8.7+dfsg-18+rpi1+deb10u1) …
正在處理用于 libc-bin (2.28-10+rpi1) 的觸發器 …

安裝 libhdf5-devt

pi@raspberrypi:~/Desktop $ sudo apt-get install libhdf5-dev -y

安裝完以上內容后,才能使用opencv-python庫

測試 opencv-python能否使用:

pi@raspberrypi:~/Desktop $ python3
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
>>> cv2.version
‘4.1.0’

顯示版本號后,說明opencv-python庫可以被使用了。


指令集為:aarch64下,可以嘗試使用 apt 安裝 python3-opencv

sudo apt install python3-opencv

pi@raspbian:~/桌面$ sudo apt install python3-opencv
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following package was automatically installed and is no longer required:
libre2-5
Use ‘sudo apt autoremove’ to remove it.
The following additional packages will be installed:
autoconf automake autotools-dev gdal-data gfortran gfortran-8 libaec0 libarmadillo9 libarpack2
libcaf-openmpi-3 libcharls2 libcoarrays-dev libcoarrays-openmpi-dev libdap25 libdapclient6v5
libdapserver7v5 libepsilon1 libfreexl1 libfyba0 libgdal20 libgdcm2.8 libgeos-3.7.1 libgeos-c1v5
libgeotiff2 libgfortran-8-dev libgl2ps1.4 libhdf4-0-alt libhdf5-103 libhdf5-openmpi-103 libhwloc-dev
libhwloc-plugins libhwloc5 libibverbs-dev libkmlbase1 libkmlconvenience1 libkmldom1 libkmlengine1



Setting up libopencv-highgui3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-features2d3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-calib3d3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-objdetect3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-stitching3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-videostab3.2:arm64 (3.2.0+dfsg-6) …
Setting up libopencv-contrib3.2:arm64 (3.2.0+dfsg-6) …
Setting up python3-opencv (3.2.0+dfsg-6) …
Processing triggers for libc-bin (2.28-10) …
Processing triggers for man-db (2.8.5-2) …

總結

以上是生活随笔為你收集整理的OpenCV AprilTags 识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本不卡一二三区 | 成人a区 | 大尺度激情吻胸视频 | 精品中文字幕在线观看 | 成人精品福利视频 | 超碰麻豆| 日本少妇aaa | 亚洲国产高清视频 | va婷婷在线免费观看 | 女教师高潮黄又色视频 | jzjzz成人免费视频 | 少妇激情在线 | 在线免费观看av网 | 久久调教视频 | 日韩黄片一区二区三区 | 国产另类xxxxhd高清 | 在线免费观看av片 | 一区二区三区免费高清视频 | av在线播放一区二区三区 | 一进一出视频 | 老熟妇高潮一区二区三区 | 天堂va蜜桃 | 91高清网站 | 老头老太吃奶xb视频 | 最新色站 | 中文字幕成人在线视频 | 91黄色小视频 | 中国丰满老妇xxxxx交性 | 6699av| 亚洲一区二区国产精品 | 爆乳2把你榨干哦ova在线观看 | 日韩一区中文 | 成年人视频在线看 | 波多野结衣办公室双飞 | 久久久91| 可乐操亚洲 | 337p粉嫩日本欧洲亚洲大胆 | 成人免费黄色av | 日韩精品毛片 | 亚洲一区中文字幕 | 99久久精品无免国产免费 | 奇米影视四色7777 | 极品白嫩丰满少妇无套 | 国产精品视频入口 | 91成人在线视频 | 日本午夜一区二区三区 | 日韩中文字幕免费观看 | 蜜桃视频污在线观看 | 在线免费观看视频你懂的 | 亚洲一二三精品 | 中文字幕久热 | 欧美成人精品一区二区男人看 | 欧美一级淫片007 | 日韩精品你懂的 | 亚洲av无码片一区二区三区 | 中国女人一级片 | 国产成人77亚洲精品www | 黄色在线视频网址 | 亚洲黄色在线播放 | 少妇人禽zoz0伦视频 | 欧美福利视频在线 | 久操成人| 黑人粗进入欧美aaaaa | 91老师片黄在线观看 | 天堂在线观看视频 | 中文字幕高清一区 | 91精品人妻一区二区三区 | 在线观看色网站 | 成人毛片网 | 国产毛片一区二区三区 | 67194成人在线观看 | 欧美xxxx黑人 | 春色网站 | 欧美 日韩 国产在线 | 26uuu国产精品视频 | 亚洲区在线 | 超碰在线98| 国产99在线视频 | 亚欧在线免费观看 | 国产探花一区二区三区 | av一区免费 | 精品伊人久久 | 日韩精选 | 亚洲mv一区 | 亚洲毛片视频 | 中文精品无码中文字幕无码专区 | 五月开心激情网 | 欧美aa在线| 亚州综合| 日本一区二区三区在线观看视频 | 国产日韩欧美精品 | 日本黄色小说 | 熟女丰满老熟女熟妇 | 欧美三级网站在线观看 | 三级黄色小视频 | 日本三级中国三级99人妇网站 | 亚洲精品人人 | 亚洲无吗一区二区三区 | 丰满人妻一区二区三区精品高清 |