WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-07-2011, 04:58 PM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
opencv with vizard 4

Now that vizard 4 use python 2.7, some one had tried to use vizard with opencv?, i tried to install but i can't get it work.

I would like run opencv with vizard for a project that i had.
Reply With Quote
  #2  
Old 04-09-2011, 01:02 AM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
some one?? i check on the forum for open cv but is for 1.0 version, and i would like for 2.1 i some know how to use vizard with open cv 2.1
Reply With Quote
  #3  
Old 04-10-2011, 10:33 AM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
Ok, i'm experiment with opencv and this what i got:

1) I installed OpenCV-2.2.0-win32-vs2010.exe from the opecv site and i choose to install the system variables for all users.

2) I installed numpy-1.5.1-win32-superpack-python2.7.exe (because it seems that opecv need it)

3) I copy the files of C:\OpenCV2.2\Python2.7\Lib\site-packages to C:\Program Files (x86)\WorldViz\Vizard4\bin\lib\site-packages

4) i tried this code in vizard and it WORKS!!!:
Code:
import cv

cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)

while True:
    img = cv.QueryFrame(capture)
    cv.ShowImage("camera", img)
    if cv.WaitKey(10) == 27:
        break
cv.DestroyWindow("camera")
The problem is that when i tried this with another code like this one:
Code:
import Image
import cv
import viz

viz.go()

def PIL_TO_VIZARD(image,texture):
    """Copy the PIL image to the Vizard texture"""
    im = image.transpose(Image.FLIP_TOP_BOTTOM)
    texture.setImageData(im.convert('RGB').tostring(),im.size)

capture = cv.CaptureFromCAM(-1)#conectate a camara

tex = viz.addBlankTexture([1,1])
quad = viz.addTexQuad(pos=(0,1.8,2),texture = tex)

while True:
    src = cv.QueryFrame(capture)
    dst = cv.CreateImage(cv.GetSize(src),cv.IPL_DEPTH_8U,1)
    cv.CvtColor( src, dst, cv.CV_RGB2GRAY)
    #Convierto opencv to PIL image
    pil = Image.fromstring("L", cv.GetSize(dst), dst.tostring())
    #Aply image to texture
    PIL_TO_VIZARD(pil,tex)
    
    if cv.WaitKey(10) == 27:
        break
When i run this code it consumes me a lot of ram and then it freeze the machine
If anyone has a clue of what maybe is happening
Reply With Quote
  #4  
Old 04-11-2011, 03:54 AM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
Hi DarkMax,

Just wondering if you had any luck with this? All I get when is a black screen in the cvWindow instead of the stream from the webcam, most other samples from OpenCV seem to work although I haven't tried them all.

This would be a total game changer for me if Viz 4 and OpenCV can be made to play well together . . . . . . .
Reply With Quote
  #5  
Old 04-12-2011, 06:15 AM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
not yet, i'm still looking
Reply With Quote
  #6  
Old 04-22-2011, 01:13 PM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
Some that know why i can pass the image from the camera to a plane in vizard?
Reply With Quote
  #7  
Old 05-11-2011, 11:20 AM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
I resolve the problem, now i have opencv and vizard working together, just i have to use the viztask.schedule() command on the method that i use for opencv
Reply With Quote
  #8  
Old 05-12-2011, 02:35 AM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
Hi Darkmax,

Thats fantastic news, I'm still struggling to get openov to play nicely with Vizard, am even thinking of trying with pyopencv when I get a chance (writing writing writing at the moment ).

However, would it be possible for you to give me some advise as to how you have managed to get them working with each other, just a few pointers to get me started - I can use opencv with the highgui window, but am getting stuck trying to pass the video frames to the vizard render window .

Any advise would be really welcome,

best regards
Reply With Quote
  #9  
Old 05-13-2011, 06:14 AM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
try this code:
Code:
import Image
import cv
import viz
import viztask

#Quad to display the image on vizard
tex = viz.addBlankTexture([1,1])
quad = viz.addTexQuad(pos=(0,1.8,2),texture = tex)

def PIL_TO_VIZARD(image,texture):
    """Copy the PIL image to the Vizard texture"""
    im = image.transpose(Image.FLIP_TOP_BOTTOM)
    texture.setImageData(im.convert('RGB').tostring(),im.size)

def opencvMain():
	capture = cv.CaptureFromCAM(-1)#conect to a camera
	
	while True:
		src = cv.QueryFrame(capture) #Image from camera in BGR format
		dst = cv.CreateImage(cv.GetSize(src),cv.IPL_DEPTH_8U,3)
		cv.CvtColor( src, dst, cv.CV_BGR2RGB) #Converting BGR to RGB
		
		#Converting opencv image to PIL image
		pil = Image.fromstring("RGB", cv.GetSize(dst), dst.tostring())
		
		#Aply image to texture
		PIL_TO_VIZARD(pil,tex)
		
		cv.WaitKey(10)
		yield viztask.waitTime(0)
		
viztask.schedule(opencvMain())

viz.go()
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Realistic Light and Shadows Using Vizard and 3DS Max jde Vizard 4 07-13-2012 10:58 AM
Vizard 4 Beta Testing farshizzo Announcements 0 02-01-2011 10:46 AM
Vizard 4 Beta Testing farshizzo Vizard 0 02-01-2011 10:46 AM
.3DS importing in Vizard and 3D Studio jde Vizard 1 08-28-2009 03:14 PM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 11:13 AM


All times are GMT -7. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC