Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Slit Scanner Debugging

$
0
0

@nacipua1 wrote:

I currently debugging code and using looking over old code to create a slit scanner that has multi capacities.

A few of the errors I am running into are:

  1. The function movePixelsInlmage has a problem with detecting ofGetWidth(), ofGetHeight(), and
    ofGetPixels();
    Here is the error it is producing:

  2. The third option of the switch statement was an attempt to make the scanner produced from up and down, however its producing a very slow rate.


    You can see it at the top of the left box.
  3. I was looking into seeing if I can get an image, like a screen shot initially as the slit scanner was beginning to run so there wont be a black box.

  4. I’ve been attempting to see if I can each individually scanner to continue where the other has stop when the switch case has moved to another scanner.

Here is my ofApp.h file:

#pragma once

#include "ofMain.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 windowResized(int w, int h);
//  void dragEvent(ofDragInfo dragInfo);
//  void gotMessage(ofMessage msg);

    
  unsigned char* sample;
  unsigned char* sample2;
  unsigned char* sample3;
  unsigned char* imagePixels;
    
  int camWidth;
  int camHeight;
  int switchCase;
  int columnNum;
  int rowNum;
    
  int slitScanWidth;
  int slitScanGrabColumn;
    
  ofImage slitScanImage;
  ofImage image;
  ofVideoGrabber myVideoGrabber;
  ofVideoGrabber vidGrabber;
  ofTexture myTexture;
  ofTexture myTexture2;
  ofTexture myTexture3;
  ofTexture myTexture4;
    
private:
  unsigned int nrFrames;
  void movePixelsInImage(ofImage * image);
};

Here is my ofApp.cpp file:


#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup() {
  camWidth = 640; //Width of the camera
  camHeight = 480; // Height of the camera
  columnNum = 0; // Number of Column for the 'for' loop
  rowNum = 0;
  switchCase = 1;
    
  myVideoGrabber.initGrabber(camWidth, camHeight);
    
  sample = new unsigned char [camWidth * camHeight * 3];
  sample2 = new unsigned char [camWidth * camHeight * 3];
  sample3 = new unsigned char [camWidth * camHeight * 3];
  imagePixels = new unsigned char [camWidth * camHeight * 3];
    
  myTexture.allocate (camWidth, camHeight, GL_RGB);
  myTexture2.allocate (camWidth, camHeight, GL_RGB);
  myTexture3.allocate (camWidth, camHeight, GL_RGB);
  myTexture4.allocate (camWidth, camHeight, GL_RGB);

  slitScanWidth   = 1000;
  slitScanGrabColumn = 240;
  vidGrabber.setDeviceID(0); //choose the index from the list of webcams that was printed to the console
  vidGrabber.setUseTexture(true);
  vidGrabber.setDesiredFrameRate(60);
  vidGrabber.initGrabber(camWidth,camHeight);
    
  slitScanImage.allocate(slitScanWidth, camHeight, OF_IMAGE_COLOR);
  ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update() {
  myVideoGrabber.update();
  switch (switchCase) {
    case 1:
      if(myVideoGrabber.isFrameNew()) {
        unsigned char* pixelData = myVideoGrabber.getPixels().getData();
        //Get the 1pixel from the orgin cam
        //  unsigned char* imagePixels = slitScanImage.getPixels().getData();
        // movePixelsInImage(&slitScanImage);
        int rowNumInPixels, columnNumInPixels, mouseXInPixels;
          
        for(int row=0; row<camHeight; row++) {
          rowNumInPixels = row * camWidth * 3;
          for(int cc=0; cc<3; cc++) {
            columnNumInPixels = columnNum * 3;
            mouseXInPixels = mouseX * 3;
            sample[rowNumInPixels + columnNumInPixels + cc] = pixelData[rowNumInPixels + mouseXInPixels + cc];
          }
        }
        columnNum++;
        myTexture.loadData (sample, camWidth,camHeight, GL_RGB);
      }
    break;
          
    case 2:
      if(myVideoGrabber.isFrameNew()) {
        unsigned char* pixelData = myVideoGrabber.getPixels().getData();
        int v1 = ofRandom(0,8);
        int rowNumInPixels, columnNumInPixels, mouseXInPixels;
          
        for(int column = 0; column < camWidth; column++) {
          columnNumInPixels = column * camHeight * 3;
          for(int cc=0; cc<v1; cc++) {
            rowNumInPixels = rowNum * 3;
            mouseXInPixels = mouseX * 3;
            sample2[columnNumInPixels + rowNumInPixels + cc] = pixelData[columnNumInPixels + mouseXInPixels + cc];
          }
        }
                
        rowNum++;
        myTexture2.loadData (sample2, camWidth,camHeight, GL_RGB);
      }
      break;
            
    case 3:
      if(myVideoGrabber.isFrameNew()) { //Checks if there is a newFrame
        unsigned char* pixelData = myVideoGrabber.getPixels().getData();
        int rowNumInPixels, columnNumInPixels, mouseXInPixels;
        for(int row=0; row<camWidth; row++) {
          rowNumInPixels = row * 3;
          columnNumInPixels = columnNum * 3;
          mouseXInPixels = mouseX * 3;
            
          sample3[rowNumInPixels + columnNumInPixels + 1] = pixelData[rowNumInPixels + mouseXInPixels + 1];
          sample3[rowNumInPixels + columnNumInPixels + 2] = pixelData[rowNumInPixels + mouseXInPixels + 2];
          sample3[rowNumInPixels + columnNumInPixels + 3] = pixelData[rowNumInPixels + mouseXInPixels + 3];
        }
      columnNum++;
      myTexture3.loadData (sample3, camWidth,camHeight, GL_RGB);
    }
    break;
          
  case 4:
          unsigned char * videoPixels = vidGrabber.getPixels().getData();
          unsigned char * imagePixels = slitScanImage.getPixels().getData();
          
          movePixelsInImage(&slitScanImage);
          
          for (int x = 0; x < camWidth; x++) {
              //change to camWidth, x++
              int imagePosition = ((camWidth*camHeight*3)) + (x)*3;
              int videoPosition = (x)*3;
              imagePixels[imagePosition]   = videoPixels[videoPosition];
              imagePixels[imagePosition+1] = videoPixels[videoPosition+1];
              imagePixels[imagePosition+2] = videoPixels[videoPosition+2];
          }
          slitScanImage.update();
        myTexture4.loadData (imagePixels, camWidth,camHeight, GL_RGB);
    break;
    }
}

void ofApp::movePixelsInImage(ofImage * image) {
    unsigned char * pixels = image->getPixels(); //equivalent to (*image).getPixels();
    for (int x=0; x<image->ofGetWidth()-1; x++) {
        for (int y=0; y<image->ofGetHeight(); y++) {
            int position = y*(image->ofGetWidth() * 3)+x*3;
            int nextPosition = position+3;
            pixels[position] = pixels[nextPosition];
            pixels[position+1] = pixels[nextPosition+1];
            pixels[position+2] = pixels[nextPosition+2];
        }
    }
    image->update();
}

//--------------------------------------------------------------
void ofApp::draw() {
    
  myVideoGrabber.draw(0,0);
  ofDrawLine(mouseX,0,mouseX,camHeight);
    
  if (switchCase == 1) {
    myTexture.draw(650, 0);
  }
  if (switchCase == 2) {
    myTexture2.draw(650, 0);
  }
  if (switchCase == 3) {
    myTexture3.draw(650,0);
  }
  if (switchCase == 4) {
    myTexture4.draw(650,0);
  }
    
}

void ofApp::keyPressed(int key) {
    
  if (key == '1') {
      switchCase = 1;
  } else if (key == '2') {
      switchCase = 2;
  } else if (key == '3') {
      switchCase = 3;
  }else if (key == '4') {
      switchCase == 4;
  }
    
}

Many Thanks!

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles