We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpProcessing Implementations › Ruby-Processing and NyARToolkit
Page Index Toggle Pages: 1
Ruby-Processing and NyARToolkit (Read 2116 times)
Ruby-Processing and NyARToolkit
Feb 28th, 2009, 5:53pm
 
I'm trying to bring the NyARToolkit java libraries into my rp5 sketch.  I've tried to take into account the advice in the thread about the Minim library.

There are 2 .jar files, NyAR2.jar and NyARToolkit.jar and they seem to load just fine.

My issue is that when I try to make a new instance of the NyARBoard class (inside of NyAR2, at jp.nyalta.nyar4psg.NyARBoard), I get `const_missing': uninitialized constant Artooltest::NyARBoard (NameError)

Here's my sketch:
=================================================
require 'ruby-processing'

class Artooltest < Processing::App
 load_library "video"
 load_library "NyAR2"
 load_library "NyARToolkit"
 include_package "processing.video"
 include_package "procesing.opengl"
 import "jp.nyalta.nyar4psg"
 import "javax.media.opengl"
 
 puts "NyAR2 loaded" if library_loaded? :NyAR2
 puts "NyARToolkit loaded" if library_loaded? :NyARToolkit

 def setup
   @cam = Capture.new(self, width, height, 30)
   @nya = NyARBoard.new(self, width, height, "camera_para.dat", "patt.hiro", 80)
   
 end
 
 def draw
   @cam.read if @cam.available
   
   image @cam, 0, 0
 
 end
 
end

Artooltest.new :title => "Artooltest", :width => 800, :height => 600
===================================================

The sketch returns "NyAR2 loaded" and "NyARToolkit loaded" before spitting out that error I mentioned:

`const_missing': uninitialized constant Artooltest::NyARBoard (NameError)
Re: Ruby-Processing and NyARToolkit
Reply #1 - Mar 3rd, 2009, 3:42am
 
When you can't find a given class, try looking from the top level (perhaps with rp5 live):

Jp::Nyalta::Nyar4psg::NyARBoard

Or some differently-capitalized variant thereof.

You can always call "constants" on a class to see what constants are in it's scope, so Artooltest.constants might give you some clues.

For reference, here's the JRuby page on importing and accessing java classes:

http://wiki.jruby.org/wiki/Calling_Java_from_JRuby
Re: Ruby-Processing and NyARToolkit
Reply #2 - Mar 3rd, 2009, 4:26pm
 
Thanks, I was able to fix it using the live view.  The issue, embarrassingly enough, was that I misspelled nyatla as nyalta.

This means that a failure in the line:
import "jp.nyalta.nyar4psg"
passed silently, as far as I can tell.  Is there some way to get feedback about a failed import?

Edit:
This works:
==============================
require 'ruby-processing'

class Artooltest < Processing::App
 load_library "video"
 load_library "opengl"
 load_library 'NyAR2'
 load_library 'NyARToolkit'
 include_package "processing.video"
 include_package "procesing.opengl"
 import 'jp.nyatla.nyar4psg'
 import "javax.media.opengl"

 puts "NyAR2 loaded" if library_loaded? :NyAR2
 puts "NyARToolkit loaded" if library_loaded? :NyARToolkit

 def setup
   render_mode OPENGL
   frame_rate 15
   
   @cam = Capture.new(self, width, height, 30)
   @nya = NyARBoard.new(self, width, height, "camera_para.dat", "patt.hiro", 80)
   @nya.gsThreshold=120
   @nya.cfThreshold=0.4
   
   image_mode CORNERS
 end
 
 def draw
   @cam.read if @cam.available
   image @cam, 0, 0
   
   fill(220, 20, 20)
   
   @nya.detect(@cam) ? (puts "yup") : (puts "nope")
   
   (0..3).each do |num|
     ellipse(@nya.pos2d[num][0], @nya.pos2d[num][1], 20, 20)
   end
 
 end
 
end

Artooltest.new :title => "Artooltest", :width => 640, :height => 480
==================================

You need to have the camera_para.dat and patt.hiro files in the root folder of the sketch, and NyAR2.jar in library/NyART2/ and NyARToolkit in library/NyARToolkit.

Now I'm trying to figure out how to do this part of the example pde sketch:

   PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
   nya.beginTransform(pgl);
   noFill();
   stroke(255,200,0);
   translate(0,0,20);
   box(40);
   nya.endTransform();

PGraphicsOpenGL is apparently derived from PImage, but I'm having some trouble figuring out where it lives.  I seems to make a new instance of a class, but I'm not sure what the "g" is all about.
Page Index Toggle Pages: 1