- OpenCV 4 with Python Blueprints
- Dr. Menua Gevorgyan Arsen Mamikonyan Michael Beyeler
- 377字
- 2021-06-24 16:50:03
Utilizing OpenNI-compatible sensors
To use an OpenNI-compatible sensor, you must first make sure that OpenNI2 is installed and that your version of OpenCV was built with the support of OpenNI. The build information can be printed as follows:
import cv2
print(cv2.getBuildInformation())
If your version was built with OpenNI support, you will find it under the Video I/O section. Otherwise, you will have to rebuild OpenCV with OpenNI support, which is done by passing the -D WITH_OPENNI2=ON flag to cmake.
After the installation process is complete, you can access the sensor similarly to other video input devices, using cv2.VideoCapture. In this app, in order to use an OpenNI-compatible sensor instead of a Kinect 3D sensor, you have to cover the following steps:
- Create a video capture that connects to your OpenNI-compatible sensor, like this:
device = cv2.cv.CV_CAP_OPENNI capture = cv2.VideoCapture(device)
If you want to connect to Asus Xtion, the device variable should be assigned to the cv2.CV_CAP_OPENNI_ASUS value instead.
- Change the input frame size to the standard Video Graphics Array (VGA) resolution, as follows:
capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640) capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
- In the previous section, we designed the read_frame function, which accesses the Kinect sensor using freenect. In order to read depth images from the video capture, you have to change that function to the following one:
def read_frame():
if not capture.grab():
return False,None
return capture.retrieve(cv2.CAP_OPENNI_DEPTH_MAP)
You will note that we have used the grab and retrieve methods instead of the read method. The reason is that the read method of cv2.VideoCapture is inappropriate when we need to synchronize a set of cameras or a multi-head camera, such as a Kinect.
For such cases, you grab frames from multiple sensors at a certain moment in time with the grab method and then retrieve the data of the sensors of interest with the retrieve method. For example, in your own apps, you might also need to retrieve a BGR frame (standard camera frame), which can be done by passing cv2.CAP_OPENNI_BGR_IMAGE to the retrieve method.
So, now that you can read data from your sensor, let's see how to run the application in the next section.
- Getting Started with React
- Vue.js前端開發(fā)基礎(chǔ)與項目實戰(zhàn)
- PyQt從入門到精通
- Mastering QGIS
- Neo4j Essentials
- OpenNI Cookbook
- 深入淺出Windows API程序設(shè)計:編程基礎(chǔ)篇
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Learning Python Design Patterns(Second Edition)
- JavaScript應(yīng)用開發(fā)實踐指南
- 人人都能開發(fā)RPA機器人:UiPath從入門到實戰(zhàn)
- 精通Spring:Java Web開發(fā)與Spring Boot高級功能
- Python 快速入門(第3版)
- Python GUI設(shè)計tkinter菜鳥編程(增強版)
- 中小企業(yè)網(wǎng)站建設(shè)與管理(靜態(tài)篇)