0

So what i'm basically trying to do is converting the pixel in image to the color i want, i'm not finding anything in openCV for java , the only way i come up with is this :

     for (int i = 0; i < image.cols(); i++) {
     for (int j = 0; j < image.rows(); j++) {

     double[] data = image.get(i, j);
     data[0] = 255;
     data[1] = 255;
     data[2] = 255;
     image.put(i, j, data);
     }
     }
     Utils.matToBitmap(image, bmp);
     return bmp;;

trying to imtate this c++ code in java, but its not working

Community
  • 1
  • 1
A.AL
  • 135
  • 3
  • 12
  • is this c++ or java? – Boyko Perfanov May 27 '15 at 19:02
  • no this is java and i'm trying to imitate the c++ code – A.AL May 27 '15 at 19:13
  • do not try to imitate c++ code. use higher level functions, like `image.setTo(Scalar.all(255))` – berak May 27 '15 at 19:48
  • if you **ever** try to access pixels like that from java - you're doing it wrong. – berak May 27 '15 at 19:50
  • thanks i found out why it was not working with me, is should use ` for (int i = 0; i < image.height(); i++) { for (int j = 0; j < image.width(); j++) { ` but i'm gonna try ` image.setTo(Scalar.all(255)) ` , because my code is very slow , thanks again – A.AL May 27 '15 at 19:57

1 Answers1

0

ok found out why it is not working, i should have write :

for (int i = 0; i < image.height(); i++) {
            for (int j = 0; j < image.width(); j++) {

instead of :

 for (int i = 0; i < image.cols(); i++) {
     for (int j = 0; j < image.rows(); j++) {
A.AL
  • 135
  • 3
  • 12