How to change the point of "this"

edited March 2018 in Kinect

Hello everybody,recently i am programming with Processing. I want to find interest_points from two image and compare them.But now i meet some questions,my interest_points all draw in the first image. i don't know how to export code with rows,so sorry.

import gab.opencv.*;
import surf.*;
ArrayList interest_points;
ArrayList interest_points_r;
float threshold = 640;
float balanceValue = 0.9;
int octaves = 4;
PImage leftimg;
PImage rightimg;


void setup(){
  size(800,800);
  leftimg=loadImage("left.png");
  rightimg=loadImage("right.png");
  leftimg.filter(GRAY);
  rightimg.filter(GRAY);
  image(leftimg, 0, 0);
  loadPixels();
  SURF_Factory mySURF = SURF.createInstance(leftimg, balanceValue, threshold, octaves, this);
  Detector detector = mySURF.createDetector();
  interest_points = detector.generateInterestPoints();
  Descriptor descriptor = mySURF.createDescriptor(interest_points);
  descriptor.generateAllDescriptors();
  drawInterestPoints();

  image(rightimg, leftimg.width, 0);
  SURF_Factory mySURF_r =SURF.createInstance(rightimg, balanceValue,threshold, octaves,this);
  Detector detector_r = mySURF_r.createDetector();
  interest_points_r = detector_r.generateInterestPoints();
  Descriptor descriptor_r = mySURF_r.createDescriptor(interest_points_r);
  descriptor_r.generateAllDescriptors();
  drawInterestPoints_r();
}
void drawInterestPoints(){ 

    println("Drawing Interest Points...");
    for(int i = 0; i < interest_points.size(); i++){

      Interest_Point IP = (Interest_Point) interest_points.get(i);
      IP.drawPosition();

    }
}

//SURF_Factory mySURF_r =SURF.createInstance(rightimg, balanceValue,threshold, octaves,this);
The"this" controls drawing interest point . In JAVA, I think i should use new to change the point of "this". But the code really confused me . surf.* library is from https://code.google.com/archive/p/p-surf/

Tagged:

Answers

  • I have corrected the code formatting above to get rid of duplicate code.

  • edited March 2018 Answer ✓

    @quark I don't know if what you did was helpful. They were trying to do the same thing twice, and so duplicated code might have been showing off what they were trying to accomplish. Without a way to see what your edit was, I am at a loss as to what their actual problem is.

    To answer your question, joke, this refers to the object that contains it. In this case, it's the parent PApplication that all your sketch's code is being run inside. There's a bunch of technical things happening under the hood that Processing has just got covered for you, and that you don't need to worry about... and this is one of them. What I'm really trying to say is that the problem isn't with the use of the this keyword. The problem is that you're always drawing interesting points at positions that are over the left image.

    My guess, since I can't exactly run this code, is that the position of an interesting point is relative to the top-right corner OF THE IMAGE - not the SKETCH.

    So if this is the code that draws interesting points over the left image:

    void drawInterestPoints_LEFT(){ 
        for(int i = 0; i < interest_points_left.size(); i++){
            Interest_Point IP = (Interest_Point) interest_points_left.get(i);
            IP.drawPosition(); 
        }
    }
    

    Then this should be the code that draws them over the right image:

    void drawInterestPoints_RIGHT(){
        pushMatrix();
        translate( leftimg.width, 0 );
        for(int i = 0; i < interest_points_right.size(); i++){
            Interest_Point IP = (Interest_Point) interest_points_right.get(i);
            IP.drawPosition(); 
        }
        popMatrix();
    }
    

    Notice how there is a translate() statement in there? This moves where (0,0) is to the upper left corner of the drawn image, essentially adjusting for the fact that the image is being displayed shifted over to the right a bit. The push/popMatrix() functions save and restore the position without this adjustment.

  • @TfGuy44 Thank you so much,you are so nice .I have solved my question

  • @quark I can't see your code,sorry

  • I think quark means he edited the code in your post...?

  • edited March 2018

    @TfGuy44 The OP had trouble formatting the code for the forum so created a new comment with the code in i..e. duplicated code (no change there then !!!)

    I simply corrected the formatting in the original comment and deleted the comment with the duplicate code.

    @joke I did not add any code, so there was none to see!

Sign In or Register to comment.