I m working on number plate recognition sys. plz improve my code.

edited March 2016 in JavaScript Mode
/**
 * Edge Detection. 
 * 
 * A high-pass filter sharpens an image. This program analyzes every
 * pixel in an image in relation to the neighboring pixels to sharpen 
 * the image. This example is currently not accurate in JavaScript mode.
 */

// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moon.jpg"; */

float[][] kernel2 = {
  {
    -1, 0, 1
  }
  , //vertical edge detection
  {
    -1, 0, 1
  }
  , 
  {
    -1, 0, 1
  }
};

float[][] kernel = {
  { 
    1, 1, 1
  }
  , //horizantal edge detection
  { 
    0, -10, 0
  }
  , 
  { 
    1, 1, 1
  }
};
//int[] a;
int d=0;
int k=0;
int b=0;
int k2=0;
int d1=0;
int d2=0;
int back;
PImage img;
PImage img1;
PImage img3;

void setup() { 
  size(700, 450);  
  img = loadImage("car4.jpg"); // Load the original image
  noLoop();
}

void draw() {
  int[] a = new int[width];
  int[] b = new int[height];
  int[] c = new int[height];


  img.loadPixels();
  // Create an opaque image of the same size as the original
  PImage edgeImg = createImage(img.width, img.height, RGB);

  //image(edgeImg, 0, 0); // Displays the image from point (0,0)
  //filter(ERODE);
  //filter(THRESHOLD,0.3);
  edgeImg.updatePixels();
  save("5.jpg");  

  PImage img2 = loadImage("black.png");
  //----------------------------------------------------------------------------------------------

  for (int y = 1; y < img.height-1; y++) { // Skip top and bottom edges      //noise elemination
    for (int x = 1; x < img.width-1; x++) { // Skip left and right edges
      float sum = 0; // Kernel sum for this pixel
      float s = 0; // Kernel sum for this pixel
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // Image is grayscale, red/green/blue are identical
          float val = red(img.pixels[pos]);
          // Multiply adjacent pixels based on the kernel values
          sum += kernel2[ky+1][kx+1] * val;
          //s += kernel[ky+1][kx+1] * val;
          //sum = max(kernel2[ky+1][kx+1],s);
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      edgeImg.pixels[y*img.width + x] = color(sum, sum, sum);
    }
  }
  //----------------------------------------------------------------------------------------------

  //------------------------------------------------------------------------------------------------
  println("next");
  b[10]=0;
  for (int j=10; j<= (img.height-10); j++) {        //up horizontal
    for (int i=1; i<= (img.width); i++) {
      b[j]=b[j]+edgeImg.pixels[i+((img.width)*(j-1))];
      b[j]=b[j]/10;
    }
  } 
  d=min(b);
  d=abs(d);

  for (int j=10; j<= (img.height-10); j++) {
    c[j]=abs(b[j])-d;
  }
  d=min(c);
  for (int j=10; j<= (img.height-10); j++) {
    if (c[j]==d) {
      k=j;
      break;
    }
  }
  edgeImg.blend(img2, 0, 0, width, k, 0, 0, width, k, BLEND);
  //------------------------------------------------------------------------------------------------
  // State that there are changes to edgeImg.pixels[]
  edgeImg.updatePixels();
  //image(edgeImg, 0, 0); // Draw the new image
  save("1.png");


  //------------------------------------------------------------------------------------------------    
  for (int y = 1; y < img.height-1; y++) { // Skip top and bottom edges      //noise elemination
    for (int x = 1; x < img.width-1; x++) { // Skip left and right edges
      float sum = 0; // Kernel sum for this pixel
      float s = 0; // Kernel sum for this pixel
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // Image is grayscale, red/green/blue are identical
          float val = red(img.pixels[pos]);
          // Multiply adjacent pixels based on the kernel values
          sum += kernel[ky+1][kx+1] * val;
          //s += kernel[ky+1][kx+1] * val;
          //sum = max(kernel2[ky+1][kx+1],s);
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      edgeImg.pixels[y*img.width + x] = color(sum, sum, sum);
    }
  }
  //------------------------------------------------------------------------------------------------    

  //------------------------------------------------------------------------------------------------  
  for (int j=10; j<= (img.width-10); j++) {        //left vertical
    for (int i=0; i<= (img.height-j); i++) {
      a[j]=a[j]+edgeImg.pixels[(i*img.width)+j];
      a[j]=a[j]/(2000);
    }
  }
  for (int j=10; j<= (img.width-10); j++) {
    if (a[j] == 0) {
      d1=j;
      break;
    }
  }
  edgeImg.blend(img2, 0, 0, (d1), height, 0, 0, (d1), height, BLEND);
  //------------------------------------------------------------------------------------------------
  edgeImg.updatePixels();
  //image(edgeImg, 0, 0); // Draw the new image
  save("2.png");

  //  PImage img1 = loadImage("1.png");
  //  PImage edgeImg2 = loadImage("2.png");
  //  edgeImg2.blend(img1, d1, k, width-d1, height-k, d1, k, width-d1, height-k, ADD);
  //  edgeImg2.blend(img1, 0, 0, width, k, 0, 0, width, k, DARKEST);
  //------------------------------------------------------------------------------------------------


  //==========================================REVERSE===============================================

  //----------------------------------------------------------------------------------------------

  for (int y = 1; y < img.height-1; y++) { // Skip top and bottom edges      //noise elemination
    for (int x = 1; x < img.width-1; x++) { // Skip left and right edges
      float sum = 0; // Kernel sum for this pixel
      float s = 0; // Kernel sum for this pixel
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // Image is grayscale, red/green/blue are identical
          float val = red(img.pixels[pos]);
          // Multiply adjacent pixels based on the kernel values
          sum += kernel2[ky+1][kx+1] * val;
          //s += kernel[ky+1][kx+1] * val;
          //sum = max(kernel2[ky+1][kx+1],s);
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      edgeImg.pixels[y*img.width + x] = color(sum, sum, sum);
    }
  }
  //----------------------------------------------------------------------------------------------

  //------------------------------------------------------------------------------------------------
  b[10]=0;
  for (int j=0; j<= (img.height-10); j++) {
    b[j]=0;
  }
  for (int j=k+10; j<= (img.height-10); j++) {        //down horizontal
    for (int i=1; i<= (img.width); i++) {
      b[j]=b[j]+edgeImg.pixels[i+((img.width)*(j-1))];
      b[j]=b[j]/10;
    }
  } 
  d=min(b);
  d=abs(d);

  for (int j=k+10; j<= (img.height-10); j++) {
    c[j]=abs(b[j])-d;
  }
  d=min(c);
  d=abs(d);    

  for (int j=k+10; j<= (img.height-10); j++) {
    if (c[j]==0) {
      if (c[j+1]==0) {
        if (c[j+2]==0) {
          if (c[j+3]==0) {
            k2=j;
            break;
          }
        }
      }
    }
  }
  edgeImg.blend(img2, 0, k2, width, height, 0, k2, width, height, BLEND);
  //------------------------------------------------------------------------------------------------
  // State that there are changes to edgeImg.pixels[]
  edgeImg.updatePixels();
  //image(edgeImg, 0, 0); // Draw the new image
  save("3.png");


  //------------------------------------------------------------------------------------------------    
  for (int y = 1; y < img.height-1; y++) { // Skip top and bottom edges      //noise elemination
    for (int x = 1; x < img.width-1; x++) { // Skip left and right edges
      float sum = 0; // Kernel sum for this pixel
      float s = 0; // Kernel sum for this pixel
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // Image is grayscale, red/green/blue are identical
          float val = red(img.pixels[pos]);
          // Multiply adjacent pixels based on the kernel values
          sum += kernel[ky+1][kx+1] * val;
          //s += kernel[ky+1][kx+1] * val;
          //sum = max(kernel2[ky+1][kx+1],s);
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      edgeImg.pixels[y*img.width + x] = color(sum, sum, sum);
    }
  }
  //------------------------------------------------------------------------------------------------    

  //------------------------------------------------------------------------------------------------  
  for (int j= (d1+10); j<= (img.width-10); j++) {        //right2 vertical
    for (int i=0; i<= (img.height-j); i++) {
      a[j]=a[j]+edgeImg.pixels[(i*img.width)+j];
      a[j]=a[j]/(2000);
    }
    println(j, a[j]);
  }
  for (int j= (d1+10); j<= (img.width-10); j++) {
    if (a[j] == 0) {
      d2=j;
      break;
    }
  }
  edgeImg.blend(img2, d2, 0, width, height, d2, 0, width, height, BLEND);
  //------------------------------------------------------------------------------------------------
  edgeImg.updatePixels();
  //image(edgeImg, 0, 0); // Draw the new image
  save("4.png");

  //  PImage img1 = loadImage("1.png");
  //  PImage edgeImg2 = loadImage("2.png");
  //  edgeImg2.blend(img1, d1, 0, width-d1, height, d1, 0, width-d1, height, ADD);
  //  edgeImg2.blend(img1, 0, 0, width, k, 0, 0, width, k, DARKEST);

  //  PImage img3 = loadImage("3.png");
  //  PImage edgeImg3 = loadImage("4.png");  
  //  edgeImg3.blend(img3, d2, 0, width-d2, height, d2, 0, width-d2, height, DARKEST);
  //  edgeImg3.blend(img3, 0, k2, width, height, 0, k2, width, height, DARKEST);  

  PImage img3 = loadImage("3.png");
  PImage edgeImg3 = loadImage("4.png");  
  //  img.blend(img2, d2, 0, width, height, d2, 0, width, height, DARKEST);
  //  img.blend(img2, 0, 0, width, k, 0, 0, width, k, DARKEST);
  //  img.blend(img2, 0, k2, width, height, 0, k2, width, height, DARKEST); 
  //  img.blend(img2, 0, 0, d1, height, 0, 0, d1, height, DARKEST);  

  // State that there are changes to edgeImg.pixels[]
  edgeImg.updatePixels();
  //image(img, 0, 0); // Draw the new image
  PImage Im = img.get(d1, k, d2-d1, k2-k);
  image(Im, 0, 0, d2-d1, k2-k);
  println(d1, d2);
  int[] m = new int[d2-d1];
  //for (int j=0; j<= (k2-k-1); j++) {        //up horizontal
  for (int i=0; i<= (d2-d1-1); i++) {
    m[i] = get(i, 0);
    println(i, m[i]);
  }
  //} 
  back=max(m);
  println(back);
  background(back);
}
Tagged:

Answers

Sign In or Register to comment.