View Single Post
  #3  
Old 03-14-2017, 10:50 PM
rajnishv rajnishv is offline
Member
 
Join Date: Jan 2016
Location: Kalina,Sanatcruz(East),Mumbai,Maharashtra,India
Posts: 94
H Jeff,
I am using the following code to save the pattern.
Is there any possibility using the code to get all the points and edged perfectly and save it as a pattern and then can be used to augment a 3D Model.
Or is there way to use OpenCv with AR ToolKit of Vizard combined together to get the result?

Code:
"""
Press spacebar to save highlighted pattern to file
Press F12 to display camera debugging controls
"""
import viz
import vizact
import vizinput
viz.go()

#Add ARToolkit extension
ar = viz.add('artoolkit.dle')

#Create camera from texture
camera = ar.addWebCamera()
camera.largestMarker = None



#Example for creating a set of lines: 
viz.startLayer(viz.POINTS) 
viz.vertexColor(0,0,1)
viz.pointSize(5)
viz.vertexColor(0,1,0) 

viz.vertex(-1,1,5) #Vertices are split into pairs. 
viz.vertex(-1,18,5) 

viz.vertex(-1,2,5) #Vertices are split into pairs. 
viz.vertex(-1,17,5)

viz.vertex(-1,3,5) #Vertices are split into pairs. 
viz.vertex(-1,29,5)

viz.vertex(-1,1,5) 
viz.vertex(10,2,-6)

viz.vertex(-1,3,5) 
viz.vertex(10,6,-6)


viz.vertex(-1,5,5) 
viz.vertex(10,9,-6)

viz.vertex(10,2,-6)
viz.vertex(10,18,-6)\


viz.vertex(10,3,-6)
viz.vertex(10,7,-6)

viz.vertex(10,6,-6)
viz.vertex(10,9,-6)

viz.vertex(10,18,-6)
viz.vertex(-1,18,5) 

viz.vertex(10,2,-6)
viz.vertex(40,0,-50)

viz.vertex(40,2,-50)
viz.vertex(40,18,-50)

viz.vertex(40,18,-50)
viz.vertex(10,18,-6)
 
square = viz.endLayer() 


def UpdateLargestMarker():
	"""Finds raw marker with largest pixel area"""
	raw = camera.getRawMarkers()
	if raw:
		raw.sort(key = lambda r: r.area)
		camera.largestMarker = raw[0]
		square.setMatrix( camera.getRawMarkerMatrix(raw[0],width=5000) )
		square.visible(1)
	else:
		camera.largestMarker = None
		square.visible(0)

#Update raw pattern every frame
vizact.onupdate(viz.PRIORITY_INPUT-1,UpdateLargestMarker)

def SavePattern():
	"""Displays save dialog for creating pattern from largest raw marker"""
	if camera.largestMarker is not None:
		filename = vizinput.fileSave()
		if filename:
			camera.savePattern(filename,camera.largestMarker)

#Save current pattern when spacebar is pressed
vizact.onkeyup(' ',SavePattern)

#Allow configuring camera
import vizconfig
vizconfig.register(camera)
vizconfig.getConfigWindow().setWindowAlignment(viz.ALIGN_RIGHT_BOTTOM)

Last edited by rajnishv; 03-14-2017 at 10:58 PM.
Reply With Quote