资源简介
增强现实,可直接用电脑摄像头实时实现,无需另拍视频。
代码片段和文件信息
# 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 = ‘D:/pycharmfile/augmented-reality-master/augmented-reality-master/‘
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(d
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-04-06 22:45 augmented-reality-master\
文件 1203 2019-01-05 09:36 augmented-reality-master\.gitignore
目录 0 2019-04-06 23:08 augmented-reality-master\.idea\
文件 468 2019-04-06 22:52 augmented-reality-master\.idea\augmented-reality-master.iml
文件 138 2019-04-06 22:45 augmented-reality-master\.idea\encodings.xm
文件 188 2019-04-06 22:45 augmented-reality-master\.idea\misc.xm
文件 307 2019-04-06 22:45 augmented-reality-master\.idea\modules.xm
文件 6996 2019-04-06 23:08 augmented-reality-master\.idea\workspace.xm
文件 1077 2019-01-05 09:36 augmented-reality-master\LICENSE
目录 0 2019-04-06 22:44 augmented-reality-master\models\
文件 73379 2019-01-05 09:36 augmented-reality-master\models\cow.obj
文件 53540 2019-01-05 09:36 augmented-reality-master\models\fox.obj
文件 6186 2019-01-05 09:36 augmented-reality-master\models\pirate-ship-fat.obj
文件 48596 2019-01-05 09:36 augmented-reality-master\models\rat.obj
文件 201102 2019-01-05 09:36 augmented-reality-master\models\wolf.obj
文件 2627 2019-01-05 09:36 augmented-reality-master\README.md
目录 0 2019-04-06 22:59 augmented-reality-master\reference\
文件 161116 2019-04-06 22:59 augmented-reality-master\reference\front.jpg
文件 42588 2019-01-05 09:36 augmented-reality-master\reference\model.jpg
目录 0 2019-04-06 23:03 augmented-reality-master\src\
目录 0 2019-04-06 22:55 augmented-reality-master\src\__pycache__\
文件 1230 2019-04-06 22:55 augmented-reality-master\src\__pycache__\objloader_simple.cpython-37.pyc
文件 7199 2019-04-06 23:03 augmented-reality-master\src\ar_main.py
文件 1757 2019-04-06 22:55 augmented-reality-master\src\objloader_simple.py
相关资源
- arcgis链接合集
- 智慧考试ewei_examV3.9.2.1.rar
- Arduino I2Cdev库
- fullcalendar-3.9.0 日历控件
- udev-080.tar.bz2
- WORKNC17后处理.rar
- visio2010_150911.rar
- rpc.rstatd-4.0.1.tar.gz
- CSharpModBusExample
- S3C2440资料3时钟控制器,电源
- AR模型参数估计随机信号处理
- A first book of Ansi C Solutions to Exercises (
- 基于verilog的串口实现
- VMware Horizon View 6 key
- authorware加减法
- razavi visio electronic device library
- 831006钻直径25的孔零件图工序卡夹具图
- 超级多线程百度baidu ping.rar
- ZooKeeper分布式专题与Dubbo微服务入门
- 使用geoserver发布arcgis切片
- 卫星位置解算.rar
- ws.hbang.newterm2_2.0_iphoneos-arm[1249].deb
- 学生成绩管理系统+数据库课程设计
- Wireshark协议插件 smgp
- Quartus II 12.1 32 64破解
- arcgis api for js +json 实现热力图
- arcgis api for js 自定义弹出专题图(饼
- 使用quartz实现不重启服务器修改自定
- 最近翻译了一篇2018年人脸识别综述
- arduino鼠标点击绝对坐标
评论
共有 条评论