Advertisement
lepe

opencv-vala-matrix-example

Jan 18th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.90 KB | None | 0 0
  1. /*
  2.  * Simple example on how to test OpenCV library
  3.  * It loads an image (loaded as grayscale) and converts it to a Matrix.
  4.  * The matrix is transposed and read each pixel.
  5.  * Author: A.Lepe (dev@alepe.com)
  6.  *
  7.  * To compile: valac --pkg opencv opencv.vala
  8.  */
  9.  
  10. using OpenCV;
  11.  
  12. void main (string[] args) {
  13.     IPL.Image img = new IPL.Image.load("/var/www/test/image.jpg", IPL.Image.LoadType.GRAYSCALE);
  14.     stdout.printf("Width: %d\n", img.width);
  15.     stdout.printf("Height: %d\n", img.height);
  16.  
  17.     Matrix mat = new Matrix(img.height, img.width, OpenCV.Type.FC32_1);
  18.     OpenCV.Array.convert(img, mat);
  19.     Matrix matt = new Matrix(img.width, img.height, OpenCV.Type.FC32_1);
  20.     mat.transpose(matt);
  21.  
  22.     for(int x = 0; x < img.width - 1; x++) {
  23.         for(int y = 0; y < img.height - 1; y++) {
  24.             stdout.printf("%d ", (int)matt.get(x,y));
  25.         }
  26.         stdout.printf("\n");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement