资源简介
AR、增强现实的视频实现的完整代码,用电脑摄像头直接实现。亲测可用
代码片段和文件信息
# Useful links
# http://www.pygame.org/wiki/OBJFileLoader
# https://rdmilligan.wordpress.com/2015/10/15/augmented-reality-using-opencv-opengl-and-blender/
# https://clara.io/library
# TODO -> Implement command line arguments (scale model and object to be projected)
# -> Refactor and organize code (proper funcition definition and separation classes error handling...)
import argparse
import cv2
import numpy as np
import math
import os
from objloader_simple import *
# Minimum number of matches that have to be found
# to consider the recognition valid
MIN_MATCHES = 10
def main():
“““
This functions loads the target surface image
“““
homography = None
# matrix of camera parameters (made up but works quite well for me)
camera_parameters = np.array([[800 0 320] [0 800 240] [0 0 1]])
# create ORB keypoint detector
orb = cv2.ORB_create()
# create BFMatcher object based on hamming distance
bf = cv2.BFMatcher(cv2.NORM_HAMMING crossCheck=True)
# load the reference surface that will be searched in the video stream
dir_name = ‘E:/PycharmProjects/augmented-reality/‘
model = cv2.imread(os.path.join(dir_name ‘reference/front.jpg‘) 0)
# Compute model keypoints and its descriptors
kp_model des_model = orb.detectAndCompute(model None)
# Load 3D model from OBJ file
obj = OBJ(os.path.join(dir_name ‘models/rat.obj‘) swapyz=True)
# init video capture
cap = cv2.VideoCapture(0)
while True:
# read the current frame
ret frame = cap.read()
if not ret:
print (“Unable to capture video“)
return
# find and draw the keypoints of the frame
kp_frame des_frame = orb.detectAndCompute(frame None)
# match frame descriptors with model descriptors
matches = bf.match(des_model des_frame)
# sort them in the order of their distance
# the lower the distance the better the match
matches = sorted(matches key=lambda x: x.distance)
# compute Homography if enough matches are found
if len(matches) > MIN_MATCHES:
# differenciate between source points and destination points
src_pts = np.float32([kp_model[m.queryIdx].pt for m in matches]).reshape(-1 1 2)
dst_pts = np.float32([kp_frame[m.trainIdx].pt for m in matches]).reshape(-1 1 2)
# compute Homography
homography mask = cv2.findHomography(src_pts dst_pts cv2.RANSAC 5.0)
if args.rectangle:
# Draw a rectangle that marks the found model in the frame
h w = model.shape
pts = np.float32([[0 0] [0 h - 1] [w - 1 h - 1] [w - 1 0]]).reshape(-1 1 2)
# project corners into frame
dst = cv2.perspectiveTransform(pts homography)
# connect them with lines
frame = cv2.polylines(frame [np.int32(dst)] True 255 3 cv2.LINE_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1203 2019-01-05 09:36 augmented-reality\.gitignore
文件 501 2019-04-07 13:17 augmented-reality\.idea\augmented-reality-master.iml
文件 138 2019-04-06 22:45 augmented-reality\.idea\encodings.xm
文件 188 2019-04-07 13:17 augmented-reality\.idea\misc.xm
文件 307 2019-04-06 22:45 augmented-reality\.idea\modules.xm
文件 9393 2019-04-07 13:20 augmented-reality\.idea\workspace.xm
文件 1077 2019-01-05 09:36 augmented-reality\LICENSE
文件 73379 2019-01-05 09:36 augmented-reality\models\cow.obj
文件 53540 2019-01-05 09:36 augmented-reality\models\fox.obj
文件 6186 2019-01-05 09:36 augmented-reality\models\pirate-ship-fat.obj
文件 48596 2019-01-05 09:36 augmented-reality\models\rat.obj
文件 201102 2019-01-05 09:36 augmented-reality\models\wolf.obj
文件 2627 2019-01-05 09:36 augmented-reality\README.md
文件 161116 2019-04-06 22:59 augmented-reality\reference\front.jpg
文件 7170 2019-04-07 13:21 augmented-reality\src\ar_main.py
文件 1757 2019-04-06 22:55 augmented-reality\src\objloader_simple.py
文件 1371 2019-04-07 13:17 augmented-reality\src\__pycache__\objloader_simple.cpython-35.pyc
文件 1230 2019-04-06 22:55 augmented-reality\src\__pycache__\objloader_simple.cpython-37.pyc
目录 0 2019-04-07 13:17 augmented-reality\src\__pycache__
目录 0 2019-04-07 13:21 augmented-reality\.idea
目录 0 2019-04-06 22:44 augmented-reality\models
目录 0 2019-04-07 13:20 augmented-reality\reference
目录 0 2019-04-07 13:21 augmented-reality\src
目录 0 2019-04-06 22:45 augmented-reality
----------- --------- ---------- ----- ----
570881 24
相关资源
- wireshark GPON OMCI报文解析lua
- 4412 GPIO驱动程序、蜂鸣器实现音乐播
- 三元组相关算法含设计报告.rar
- R语言最新实现ARFIMA模型代码及参考文
- bigmart销售数据集
- VAR模型及蒙特卡罗模拟张晓彤
- RS485_Verilog.rar
- demo485.rar
- 集码客户端.rar
- graph and chart 手册
- dcsssfdf.rar
- C1StudioEnterprise_Keygen1.rar
- 学校小测试:nodejs实现简单购物车.
- 工程训练物料搬运小车OpenCV程序.rar
- 基于Arduino的PM2.5和空气湿度检测装置
- IEEE 1471 软件架构标准
- 双闭环直流调速系统动态仿真模型.
- 手势识别传感器paj7620 arduino板使用代
- 很完整的发明专利申请文件完整版模
- icinga-nrpe-2.14.tar.zip
- CARIS GIS 4.5
- Cognex Designer Sales Training 实战范例_Pa
- kepserverex v6 补丁
- 自动Dump核心转储文件.rar
- DynamicDataDisplayTest.rar
- 微信教师布置作业批改作业小程序.
- Flash 星星坠落 鼠标移动效果.rar
- 批量抓取邮箱地址(EasyEmailExtractor)
- 单元级联高压STATCOM仿真-cascaded_Hbrid
- 微信小程序版-简洁论坛类APP源码.ra
评论
共有 条评论