Question : How to use the processing core library to create a PIMAGE in Java Netbeans?

I am using the opencv Library for Java found here: http://ubaa.net/shared/processing/opencv/.  However, openCV is not compatible with my Acer Crystal Webcam, so I used a JMyron library from the Processing website to load the camera in the Processing IDE.  Now I'm trying to port everything over to NetBeans, but I have 1 error that stems from the processing libraries causing a conflict with java.  The createImage method is a PApplet method in processing but is conflicting with the java.awt createImage method.  Does anyone know how initialize a processing PImage in java without causing the error below?  I have attached the code for your review.

C:\Users\tflock\Desktop\netbeans\FaceDetection\src\facedetection\FaceDetection.java:52: non-static method createImage(int,int,int) cannot be referenced from a static context
        myImg = PApplet.createImage(320, 240, PConstants.ARGB);
1 error
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facedetection;

/**
 * (./) FaceDetection.java, 03/05/08
 * (by) cousot stephane @ http://www.ubaa.net/
 * (cc) some right reserved
 *
 * Sample program for "OpenCV" project.
 * Use ESC key to close the program properly.
 *
 * This sample is released under a Creative Commons Attribution 3.0 License
 * ‹ http://creativecommons.org/licenses/by/3.0/ ›
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.image.MemoryImageSource;
import hypermedia.video.OpenCV;
import JMyron.*;
import processing.core.*;
import java.lang.String.*;
//import processing.video.*;

public class FaceDetection extends Frame implements Runnable {

    // program execution frame rate (millisecond)
    final int FRAME_RATE = 1000 / 30;
    OpenCV cv = null;	// OpenCV Object
    Thread t = null;	// the sample thread
    // the input video stream image
    Image frame = null;
    public PImage myImg;
    public JMyron m;
    // list of all face detected area
    Rectangle[] squares = new Rectangle[0];

    /**
     * Setup Frame and Object(s).
     */
    FaceDetection() {

        super("Face Detection Sample");


        // OpenCV setup
        cv = new OpenCV();
        //cv.capture( 320, 240 );
        cv.allocate(320, 240);
        myImg = PApplet.createImage(320, 240, PConstants.ARGB);
        //myImg = createImage(320, 240);
        m = new JMyron();
        m.start(320, 240);
        m.findGlobs(0);
        System.out.println("Myron " + m.version());
        cv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT);


        // frame setup
        this.setBounds(100, 100, cv.width, cv.height);
        this.setBackground(Color.BLACK);
        this.setVisible(true);
        this.addKeyListener(
                new KeyAdapter() {

                    public void keyReleased(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { // ESC : release OpenCV resources
                            cv.dispose();
                            System.exit(0);
                        }
                    }
                });


        // start running program
        t = new Thread(this);
        t.start();
    }

    /**
     * Draw video frame and each detected faces area.
     */
    public void paint(Graphics g) {

        // draw image
        g.drawImage(frame, 0, 0, null);

        // draw squares
        g.setColor(Color.RED);
        for (Rectangle rect : squares) {
            g.drawRect(rect.x, rect.y, rect.width, rect.height);
        }
    }

    /**
     * Execute this sample.
     */
    public void run() {
        while (t != null && cv != null) {
            try {
                t.sleep(FRAME_RATE);
                m.update();
                //System.arraycopy(m.cameraImage(), 0, PImage(myImg), 0, (m.cameraImage()).length);
                PApplet.arrayCopy(m.cameraImage(),myImg.pixels);//copy pixels from the Jmyron Obj
                cv.copy(myImg);//copy PImage into opencv object

                // grab image from video stream
                cv.read();

                // create a new image from cv pixels data
                MemoryImageSource mis = new MemoryImageSource(cv.width, cv.height, cv.pixels(), 0, cv.width);
                frame = createImage(mis);

                // detect faces
                squares = cv.detect(1.2f, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 20, 20);

                // of course, repaint
                repaint();
            } catch (InterruptedException e) {;}
        }
    }

    /**
     * Main method.
     * @param String[]	a list of user's arguments passed from the console to this program
     */
    public static void main(String[] args) {
        System.out.println("\nOpenCV face detection sample\n");
        new FaceDetection();
    }
}

Answer : How to use the processing core library to create a PIMAGE in Java Netbeans?

following explains the error message

http://helpdesk.objects.com.au/java/how-to-fix-cannot-make-a-static-reference-to-the-non-static-method

but you don't want to be creating an applet (nor do you need to). Applets are for embedding in a web page.
Random Solutions  
 
programming4us programming4us