Interpolation OpenCV
in
Contributed Library Questions
•
2 years ago
Hi guys so i have a array of 12bit values that im getting via serial i am storing that data in an 2D array and based on the reading i get i display it as a pixel on the screen 0 - black, 4095 - White. my 2d Array is [16][8] what i would like to use bicubic interpolation on these matrix with a factor 10 how would i go about doing that? below is my test code. parssedData[][] is the 2d array i use to generate the the image on screen.
Basically what i would like to do is interpolate this array using the interpolation() function within openCV and generate the interpolated image on screen.
- //OPTOSENSOR.CLASS
- //Imports
- import processing.serial.*;
- import processing.video.*;
- import blobDetection.*;
- import fullscreen.*;
- import hypermedia.video.*;
- //Initialise Variables
- /*Setup serial*/
- Serial dataPort; //create object from serial class
- /*Setup Java fullscreen*/
- FullScreen fs; // Initialise FullScreen
- /*2D Array of objects*/
- Cell[][] grid; //create object from cell class
- /*Number of columns and rows in the grid*/
- int cols = 16; // number of columns
- int rows = 8; // number of rows
- /*Parssed data array*/
- //int [][] parssedData = new int [rows][cols];
- // Parssed Data test array
- int[][] parssedData = { {255, 189, 189, 0, 236, 189, 189, 0, 0, 189, 189, 0, 236, 189, 189, 0},
- {0, 80, 189, 189, 236, 80, 189, 189, 236, 80, 189, 189, 236, 80, 189, 189},
- {0, 0, 0, 80, 0, 0, 189, 80, 236, 0, 0, 80, 236, 0, 189, 80},
- {0, 189, 189, 80, 236, 0, 189, 80, 236, 189, 189, 80, 236, 189, 189, 80},
- {0, 189, 189, 0, 0, 0, 189, 0, 0, 189, 189, 0, 0, 189, 189, 0},
- {0, 80, 189, 189, 236, 80, 189, 189, 236, 80, 0, 189, 0, 80, 189, 189},
- {0, 0, 0, 80, 0, 0, 189, 80, 0, 0, 189, 80, 236, 0, 189, 80},
- {0, 189, 189, 80, 236, 189, 189, 80, 0, 189, 189, 80, 236, 189, 189, 80} };
- int lF = 10; // Linefeed in ASCII
- String Buff = null; // Data in Buffer
- int[][] values = new int[8][16]; // Values array to sensor data
- int numberOfSensors = 128; // Total number of sensors
- int threshold = 20; // Threshold Level
- int numPixels; // Total number of pixels on screen
- int[] bgPixels; // Array to hold toatal pixels
- int oldX = 0;
- int oldY = 0;
- int avg = 0;
- boolean flag;
- boolean bgsub;
- BlobDetection theBlobDetection;
- void setup()
- {
- //Setup application
- size(16,8);
- //size(1675,928); // initialise stage size
- frameRate (200); // set application framerate
- // dataPort = new Serial (this, Serial.list()[1],115200); // Open and initialise serial port
- // println(Serial.list()); // print out serial list
- // dataPort.write('1'); // select raw out put from sensor menu
- grid = new Cell[cols][rows]; // initialise raw feed grid
- fs = new FullScreen(this); // initialise fullscreen
- fs.setResolution(screen.width, screen.height); // get fs res and set applicaion res to fs res
- fs.setShortcutsEnabled(true); // enable fs entry shortcut ctrl+f
- numPixels = width*height; // calculate total pixles on screen
- bgPixels = new int [numPixels]; //
- loadPixels();
- noStroke();
- smooth();
- flag = false;
- }
- void draw()
- {
- background(0);
- for (int i = 0; i < cols; i ++ ) {
- for (int j = 0; j < rows; j ++ ) {
- // Initialize each object
- grid[i][j] = new Cell(i,j,1,1,parssedData[j][i]);
- }
- }
- for (int i = 0; i < cols; i ++ ) {
- for (int j = 0; j < rows; j ++ ) {
- // Display each object
- grid[i][j].display();
- }
- }
- smooth();
- }
- // A Cell object
- class Cell {
- // A cell object knows about its location in the grid as well as its size with the variables x, y, w, h.
- float x,y; // cell x,y location
- float w,h; // cell width and height
- float data; // data for cell brightness
- // Cell Constructor
- Cell(float tempX, float tempY, float tempW, float tempH, float tempData) {
- x = tempX;
- y = tempY;
- w = tempW;
- h = tempH;
- data = tempData;// * 0.0622;
- }
- void display() {
- //stroke(100);
- // Color calculated based on live data
- colorMode(RGB, 12);
- smooth();
- noStroke();
- if (data > 3)
- {
- fill(data);
- }
- else
- {
- fill(0);
- }
- //rect(477+x,235.5+y,w,h);
- rect(1+x,1+y,w,h);
- println(data);
- }
- }
1