text
stringlengths 1
93.6k
|
|---|
# Drawing gaze lines and sparks
|
for gaze_line in gaze_lines:
|
draw_gaze_line(out_img, (gaze_line[0][0], gaze_line[0][1]), (gaze_line[1][0], gaze_line[1][1]), laser_flag)
|
if gaze_line[2]==True:
|
draw_spark(out_img, (gaze_line[1][0], gaze_line[1][1]))
|
cv2.imshow("gaze", out_img)
|
key = cv2.waitKey(1)
|
if key == 27: break
|
if key == ord(u'l'): laser_flag = True if laser_flag == False else False # toggles laser_flag
|
if key == ord(u'f'): flip_flag = True if flip_flag == False else False # image flip flag
|
if key == ord(u'b'): boundary_box_flag = True if boundary_box_flag== False else False # boundary box flag
|
if key == ord(u's'): spark_flag = True if spark_flag == False else False # spark flag
|
cv2.destroyAllWindows()
|
if __name__ == '__main__':
|
sys.exit(main() or 0)
|
# <FILESEP>
|
# some functions for creation and rendering of 3d objects were borrowed/inspired from
|
# Juan Gallostra Acín's repository - https://github.com/juangallostra/augmented-reality
|
'''
|
Copyright (c) 2018 Juan Gallostra Acín
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
of this software and associated documentation files (the "Software"), to deal
|
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
The above copyright notice and this permission notice shall be included in all
|
copies or substantial portions of the Software.
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
'''
|
#contains code to the .obj file and augment the object
|
import cv2
|
import numpy as np
|
def augment(img, obj, projection, template, scale = 4):
|
# takes the captureed image, object to augment, and transformation matrix
|
#adjust scale to make the object smaller or bigger, 4 works for the fox
|
h, w = template.shape
|
vertices = obj.vertices
|
img = np.ascontiguousarray(img, dtype=np.uint8)
|
#blacking out the aruco marker
|
a = np.array([[0,0,0], [w, 0, 0], [w,h,0], [0, h, 0]], np.float64 )
|
imgpts = np.int32(cv2.perspectiveTransform(a.reshape(-1, 1, 3), projection))
|
cv2.fillConvexPoly(img, imgpts, (0,0,0))
|
#projecting the faces to pixel coords and then drawing
|
for face in obj.faces:
|
#a face is a list [face_vertices, face_tex_coords, face_col]
|
face_vertices = face[0]
|
points = np.array([vertices[vertex - 1] for vertex in face_vertices]) #-1 because of the shifted numbering
|
points = scale*points
|
points = np.array([[p[2] + w/2, p[0] + h/2, p[1]] for p in points]) #shifted to centre
|
dst = cv2.perspectiveTransform(points.reshape(-1, 1, 3), projection)#transforming to pixel coords
|
imgpts = np.int32(dst)
|
cv2.fillConvexPoly(img, imgpts, face[-1])
|
return img
|
class three_d_object:
|
def __init__(self, filename_obj, filename_texture, color_fixed = False):
|
self.texture = cv2.imread(filename_texture)
|
self.vertices = []
|
self.faces = []
|
#each face is a list of [lis_vertices, lis_texcoords, color]
|
self.texcoords = []
|
for line in open(filename_obj, "r"):
|
if line.startswith('#'):
|
#it's a comment, ignore
|
continue
|
values = line.split()
|
if not values:
|
continue
|
if values[0] == 'v':
|
#vertex description (x, y, z)
|
v = [float(a) for a in values[1:4] ]
|
self.vertices.append(v)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.