资源简介
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
相关资源
- EPSON XP225 xp235 xp245打印机清零软件+教
- PID_AutoTune_v0.rar
- IAR FOR 430 破解工具
- 西门坡论坛pb框架 普通版 2.0 非常漂
- 条码字体barcode128
- DV泵加罗茨泵独立控制系统PID.smart
- Xamarin forms 手势事件
- 秒杀360加壳.rar
- 200smart单按钮启停.smart
- IAR For ARM 7.3最新注册机
- 郭天祥ARM9视频教程
- IAR7.20H破解机注册机
- IAR ARM 7.8破解
- IAR 7.80.4的安装包
- IAR for MSP430 v7.10.1 注册机
- IAR-Keygen-2019+附使用教程.zip
- IAR 7.3 注册机
- IAR For ARM V5.5 注册机
- IAR for ARM 7.40 破解
- IAR For ARM 7.4 破解
- Reparatory Effects of Nicotine on NMDA Recepto
- Histamine excites rat lateral vestibular nucle
- Diltiazem augmented pentobarbital-induced LORR
- LenovoTinkPad; Marker 5.01
- 根据硬件ID和程序ID生成注册码
- Fabrication and all-optical poling characteris
- Quartus II 15.0中仿真Altera三速以太网I
- Quartus II 15.0中仿真Altera三速以太网I
- stm32f103c8t6 4 oled.rar
- VirTest5.0.rar
评论
共有 条评论