Texture mapping to ofxDelaunay mesh

Hi, I’m trying to map an image to a delaunay mesh created from an array of points. The textured mesh is showing as a single grey shape - my guess is from a single pixel of the texture stretched over its surface. How can I ensure the texture is following the triangle mesh structure?


#pragma once

#include "ofMain.h"
#include "ofxGuiExtended.h"
#include "ofxOpenCv.h"
#include "ofxMeshWarp.h"
#include "ofxMeshWarpManagedController.h"
#include "ofxDelaunay.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
    
    
        ofxGui gui;
        ofParameter <bool> objectThresholdToggle;
        ofParameter <float> objectThreshold;
        ofParameter <float> maxSize;
        ofParameter <float> minSize;
    
        ofImage img1;
        ofImage img2;
        
        ofxDelaunay triangulation;
        ofxCvContourFinder contourFinder;
        ofxCvColorImage colorImg;
        ofxCvGrayscaleImage grayImg, grayBg, grayDiff;
        ofTexture texture;
        ofEasyCam cam;
        int w, h;
    
    
    private:
		
};

#include "ofApp.h"



//--------------------------------------------------------------
void ofApp::setup(){
    
    
    ofEnableSmoothing();
    ofBackground(0);
    ofSetWindowShape(800, 1000);
    
    w = ofGetWidth();
    h = ofGetHeight();
    
    
    /////// UI
    
    gui.add(objectThreshold.set("threshold", 90, 0, 255));
    gui.add(objectThresholdToggle.set("thresholdToggle", 0, 0, 1));
    gui.add(maxSize.set("max", 400000, 0, 400000));
    gui.add(minSize.set("min", 0, 0, 20000));
    
    
    /////// IMAGES
    
    img1.load("images/img1.jpg");
    img2.load("images/img2.jpg");
    
    img1.resize(w, h);
    img2.resize(w, h);
    
    ofPixels pixels = img1.getPixels();
    
    
    ////// CONTOUR TRACKER
    
    
    colorImg.allocate(w,h);
    grayImg.allocate(w,h);
    grayBg.allocate(w,h);
    grayDiff.allocate(w,h);
    texture.allocate(w,h, GL_RGB);
    
    
    colorImg.setFromPixels(pixels);
    texture.loadData(pixels);
    
    
}

//--------------------------------------------------------------
void ofApp::update(){
    
    
    /////// FIND CONTOUR
    
    grayImg = colorImg;
    grayDiff.absDiff(grayBg, grayImg);
    if (objectThresholdToggle) grayDiff.invert();
    grayDiff.threshold(objectThreshold);
    contourFinder.findContours(grayDiff, minSize, maxSize, 1, true, true);
    
    if (contourFinder.blobs.size() != -1)  {
        int count = 10;
        int pts = contourFinder.blobs[0].pts.size();
        int skip = contourFinder.blobs[0].pts.size() / count;
        triangulation.reset();
        
        
        ////// ADD POINTS
        
        for (int i = 0; i < count; i++) {
            ofPoint xy = contourFinder.blobs[0].pts[i * skip];
            triangulation.addPoint(xy);
        }
        
        
        triangulation.triangulate();
    }
    
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    ofNoFill();
    ofSetColor(255);
    
    cam.begin();
        ofSetupScreenPerspective(w, h, 20);
        texture.bind();
            triangulation.triangleMesh.draw();
        texture.unbind();
    cam.end();
    
}

Derp - forgot to add texture coordinates :laughing: