Ask Your Question

rafaoc's profile - activity

2015-10-03 00:27:21 -0600 answered a question cv::ml::StatModel::calcError not working for responses of type CV_32S

About Question #1:
I saw also the problem with calcError and checked the source code for the function. To solve that is like you propose switching <at> float and <at> int. So:
switching

float val0 = responses.at<float>(si);

for

float val0 = responses.type()== CV_32S ? (float)responses.at<int>(si) : responses.at<float>(si);

The type evalution is needed in order to recognize if the data you have is float or integer. It because cv::ml::trainData allows integer as well float as input when you are creating it.
The casting (float) is necessary because the output of the predict function used in calcError is also float: float val = predict(sample); And val and val0 will then be compared

About Question #2
I had the same confusion and I also think the output error should be better 0 <= x <= 1

2015-08-02 11:27:48 -0600 received badge  Famous Question (source)
2015-03-05 10:22:53 -0600 received badge  Notable Question (source)
2015-01-29 11:45:10 -0600 received badge  Nice Answer (source)
2015-01-29 11:44:52 -0600 received badge  Student (source)
2015-01-29 11:44:34 -0600 received badge  Nice Answer (source)
2014-12-07 23:49:54 -0600 answered a question RGB vs. BGR

When you use the imread() opencv function to read an image. It will read a color image as BGR format, so use better BGR2gray for that transformation.

2014-12-04 22:14:40 -0600 commented question Should I use JavaCV or OpenCV's java wrapper?

I have use both, javacv and java API, and I do recommend you java API. Mainly because the documentation

2014-12-02 23:37:29 -0600 received badge  Popular Question (source)
2014-11-26 23:55:05 -0600 answered a question Display Keypoints on Image in Android - OpenCV

Look my code. It works fine

int whichDescriptor = siftDescriptor; //freakDescriptor;

        // Features SEARCH
        int detectorType = FeatureDetector.SIFT;
        FeatureDetector detector = FeatureDetector.create(detectorType);

        Mat mask = new Mat();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();
        detector.detect(image, keypoints , mask);               

        if (!detector.empty()){

            // Draw kewpoints
            Mat outputImage = new Mat();
            Scalar color = new Scalar(0, 0, 255); // BGR
            int flags = Features2d.DRAW_RICH_KEYPOINTS; // For each keypoint, the circle around keypoint with keypoint size and orientation will be drawn.
            Features2d.drawKeypoints(image, keypoints, outputImage, color , flags); 
            displayImage(Mat2BufferedImage(outputImage), "Feautures_"+detectorType);
        }

displayImage() and Mat2BufferedImage() are referenced here link1 or link2

2014-11-20 17:54:33 -0600 answered a question Should I use JavaCV or OpenCV's java wrapper?

I have worked with both api from opencv to java and javaCV and I do recommend you to work with the api. Mainly because of the documentation. Also if you dont find examples exactly for the api use, you can easily read either the c++ or the python implementation and try to find out how in java. I have realised java implementation and python are very similar.

About the gui, you can use gui builder for java. And to display an image you can create a function where the input is the image to display. See http://answers.opencv.org/question/8119/how-to-display-image-on-java-release/?answer=32135#post-id-32135

2014-11-20 17:53:02 -0600 answered a question Should I use JavaCV or OpenCV's java wrapper?

I have worked with both api from opencv to java and javaCV and I do recommend you to work with the api. Mainly because of the documentation. Also if you dont find examples exactly for the api use, you can easily read either the c++ or the python implementation and try to find out how in java. I have realised java implementation and python are very similar.

About the gui, you can use gui builder for java. And to display an image you can create a function where the input is the image to display. See http://answers.opencv.org/question/8119/how-to-display-image-on-java-release/?answer=32135#post-id-32135

2014-10-22 00:39:05 -0600 answered a question NATIVE_LIBRARY_NAME cannot be resolved or is not a field with Linux + Eclipse + Java

You have to include the library into the project path:
Project > Properties > Java Build Path > Libraries > add JARs / Add external JARs > select the opencv-XX.jar file
add JARs if you have the .jar file into the folder project. Otherwise use addd external JARs

Later, you have to modify the parameter 'Native library location' with the folder path where is the opencv library: either opencv.dll for windows or opencv.so for linux. Select the parameter and click on Edit

image description

2014-10-15 09:00:51 -0600 received badge  Teacher (source)
2014-09-25 18:04:23 -0600 commented question Is the colormap conversion of openCV linear?

Thanks Steven. I found the answer and actually these colormaps used by applyColorMap() have a linear transformation ! link

2014-09-24 08:10:16 -0600 commented question Is the colormap conversion of openCV linear?

Thanks @StevenPuttermans for your answer. May be do you have the reference where says the colormaps are based on opencv ?

2014-09-23 16:57:59 -0600 asked a question Is the colormap conversion of openCV linear?

I have a gray scale image (i.e. 1 channel). I am using the opencv function applyColorMap() to improve the visualization. For example, if I have the code below

applyColorMap(imgGray, imgOut, COLORMAP_RAINBOW);

Somebody does know if the colormap conversion is linear?

image description

image description

2014-07-25 16:03:58 -0600 commented question How convert List<Mat> to MatofPoint2f with api java for opencv

@berak: Actually, I want to convert the whole list

2014-07-25 14:57:21 -0600 asked a question How convert List<Mat> to MatofPoint2f with api java for opencv

Hi,

I am programming with the opencv api for java. And I'm trying to use the function findHomography. Its input must to be a MatofPoint2f but I have a set of points like a List(Mat).

To convert the List(Mat) to Mat I try the code below.
But I get the error: "java.lang.IllegalArgumentException: Incompatible Mat" at line

MatOfPoint2f imagePoints2f_1 = new MatOfPoint2f(mat_aux);

CODE

imagePoints_1 and imagePoints_2 are List(Mat)

Mat mat_aux;

mat_aux = Converters.vector_Mat_to_Mat(imagePoints_1);
MatOfPoint2f imagePoints2f_1 = new MatOfPoint2f(mat_aux);

mat_aux = Converters.vector_Mat_to_Mat(imagePoints_2);
MatOfPoint2f imagePoints2f_2 = new MatOfPoint2f(mat_aux);   

H = Calib3d.findHomography(imagePoints2f_1,imagePoints2f_2, Calib3d.LMEDS, 0.0);
2014-07-22 12:00:02 -0600 commented question Apply infinite homography to image

@kovand11. The matrix multiplication with gemm works good.I have already ckecked it

2014-07-20 22:36:29 -0600 commented answer Apply rotation matrix to image

Hi @kovand11 , I have tried, but I dont get good results. Could you see please the question on the link http://answers.opencv.org/question/37630/apply-infinite-homography-to-image/

2014-07-20 22:35:11 -0600 asked a question Apply infinite homography to image

Hi,
I want to apply a infinite homography to an image, but I dont know how to do it.
I'm working with the openCV api for java.
I have the below code, but I dont get good results.
From image A, I get image B
Do someone know how to apply this homography ?

image description


Calib3d.stereoCalibrate(objectPoints_1, imagePoints_1, imagePoints_2, 
    cameraMatrix_1, distCoeffs_1, cameraMatrix_2, distCoeffs_2, imageSize_1, R, T, E, F, 
    new TermCriteria( TermCriteria.MAX_ITER + TermCriteria.EPS , 30, 0.1), 
    Calib3d.CALIB_FIX_INTRINSIC );

Imgproc.initUndistortRectifyMap(cameraMatrix_1, distCoeffs_1, new Mat(), new Mat(), newImageSize_1, CvType.CV_32FC1, mapx_1, mapy_1);
Imgproc.initUndistortRectifyMap(cameraMatrix_2, distCoeffs_2, new Mat(), new Mat(), newImageSize_2, CvType.CV_32FC1, mapx_2, mapy_2);

Imgproc.remap(image_1, undistorted_1, mapx_1, mapy_1, Imgproc.INTER_LINEAR);
Imgproc.remap(image_2, undistorted_2, mapx_2, mapy_2, Imgproc.INTER_LINEAR);

Mat cameraMatrix_2_inv = new Mat(cameraMatrix_2.size(),cameraMatrix_2.type());
Core.invert(cameraMatrix_2, cameraMatrix_2_inv);
Core.invert(R, R_inv);

// inverse Homography: H_inf = k1*R*k2_inv
Mat H_inf = new Mat(3,3,CvType.CV_64FC1);
Core.gemm(cameraMatrix_1, R, 1, cameraMatrix_2_inv, 1, H_inf);

Mat outputImage_3 = new Mat();
Imgproc.warpPerspective(undistorted_2, outputImage_3, H_inf, undistorted_2.size());

2014-07-19 20:52:55 -0600 commented answer Apply rotation matrix to image

Yes, you are right , either warpPerspective() or warpAffine() are transformation on images 2d -> 2d. May be do you know how to apply an infinitive homography to an image?, i.e the matrix Hinf=k1Rk2inv, where ki are the intrinsic camera matrix and R is the rotation matrix between cameras

2014-07-19 20:49:50 -0600 received badge  Scholar (source)
2014-07-19 19:50:50 -0600 asked a question Apply rotation matrix to image

Hi,
I am working with openCV api for java.
I have a images pair and want to apply the rotation matrix which I get from

stereoCalibrate()

and I want to use it. I have try for both images, right and left, with

warpPerspective()

But it doesnt work. I get a black image.

With < warpAffine() > I dont know how to use the rotation matrix because R is 3x3 but the input for warpaffine must be 2x3

Somebody has any idea

2014-07-17 09:10:26 -0600 asked a question How could I write a roi of a cvMat with java ?

Hi, I am using java with openCV and I need to write a region of interest into a bigger matrix. Is there a way different to a for-loop to do it ?

i.e, a cvMat 50x40 into a cvMat 200x200

I know it's possible to extract a roi of a cvMat but I've not found a direct way for my problem.

In advance, thanks

2014-07-16 09:58:52 -0600 answered a question I can not run standalone Java app in Ubuntu12.04

May be in your project you don't have a local reference for the library path, try to do it.

2014-07-03 14:24:54 -0600 commented answer divide double[] into double factor

Thanks for your answer although you're programming in c++ and me in java. I got an idea

double div =  T.get(0, 0)[0] / T.get(2, 0)[0] ;
2014-07-02 23:49:49 -0600 asked a question divide double[] into double factor

Hi, I am working with opencv in java.
I have a cvMat element with three elements and I want to divide the first and the third element in order to get just the double value.
Using < T.get(0, 0) > I get a data type double[]
I have tried to make as follow
double div = T.get(0, 0) / T.get(2, 0);
or just
double div = T.get(0, 0) / 2.0d
but neither the first nor the second one are allowed

How could I do that ?

2014-06-15 23:00:30 -0600 answered a question Rotation Vectors and Translation Vectors

Hi, the parameter rvecs from cvCalibrateCamera2 is a vector of rotation vectors. It means, for each image you use for the camera calibration you will get one vector rotation. So, when you use rodrigues() you have to input each vector in order to get the matrix rotation for each image. Later you can do a minimization using the LM (Levenberg-Marquardt) algorithm to optimize the results and get R.

2014-04-24 23:42:57 -0600 received badge  Self-Learner (source)
2014-04-24 23:30:26 -0600 answered a question How load and display images with java using opencv [SOLVED]

I have done it !

You can use the next code to transform a cvMat element into a java element: BufferedImage or Image:

    public BufferedImage Mat2BufferedImage(Mat m){
// source: http://answers.opencv.org/question/10344/opencv-java-load-image-to-gui/
// Fastest code
// The output can be assigned either to a BufferedImage or to an Image

    int type = BufferedImage.TYPE_BYTE_GRAY;
    if ( m.channels() > 1 ) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels()*m.cols()*m.rows();
    byte [] b = new byte[bufferSize];
    m.get(0,0,b); // get all the pixels
    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);  
    return image;

}

And then display it with:

    public void displayImage(Image img2)
{   
    //BufferedImage img=ImageIO.read(new File("/HelloOpenCV/lena.png"));
    ImageIcon icon=new ImageIcon(img2);
    JFrame frame=new JFrame();
    frame.setLayout(new FlowLayout());        
    frame.setSize(img2.getWidth(null)+50, img2.getHeight(null)+50);     
    JLabel lbl=new JLabel();
    lbl.setIcon(icon);
    frame.add(lbl);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
2014-04-24 09:51:52 -0600 answered a question opencv + java

If you are working with Eclipse-IDE you need:

  1. Import into the project path the .jar library: opencv-246.jar
  2. Then, inside the imported library, you must edit "Native Library Location" to the folder where is your opencv-246.dll
  3. In your code call the library dll through

    System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
    

    You have to do this call just once in all the program.

More info

2014-04-24 09:43:12 -0600 asked a question How add a new element or modify one in a MatOfPoint3f ? (OpenCV, Java)

I am usig the OpenCV api for java. And I'm trying to use the MatOfPoint3f element. I find that you can initialize and insert all the data you need but once. After I insert some data, I want to maintain the old data and to insert or to modify an element.
How can I do that?

2014-04-22 13:36:07 -0600 received badge  Necromancer (source)
2014-04-22 11:33:33 -0600 answered a question How to display image on JAVA release

You can use the next code to transform a cvMat element into a java element: BufferedImage or Image:

    public BufferedImage Mat2BufferedImage(Mat m){
// source: http://answers.opencv.org/question/10344/opencv-java-load-image-to-gui/
// Fastest code
// The output can be assigned either to a BufferedImage or to an Image

    int type = BufferedImage.TYPE_BYTE_GRAY;
    if ( m.channels() > 1 ) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels()*m.cols()*m.rows();
    byte [] b = new byte[bufferSize];
    m.get(0,0,b); // get all the pixels
    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);  
    return image;

}

And then display it with:

    public void displayImage(Image img2)
{   
    //BufferedImage img=ImageIO.read(new File("/HelloOpenCV/lena.png"));
    ImageIcon icon=new ImageIcon(img2);
    JFrame frame=new JFrame();
    frame.setLayout(new FlowLayout());        
    frame.setSize(img2.getWidth(null)+50, img2.getHeight(null)+50);     
    JLabel lbl=new JLabel();
    lbl.setIcon(icon);
    frame.add(lbl);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
2014-04-09 20:13:52 -0600 received badge  Editor (source)
2014-04-09 20:13:52 -0600 edited question How load and display images with java using opencv [SOLVED]

I am working with java usign opencv. Basically I want to read and display an image using opencv functions. I wanted to translate the next code from c++ to java but i dont find the same opencv functions for java.


include "opencv2/highgui/highgui.hpp"
include "iostream"
using namespace cv;
using namespace std;
int main(){
Mat img = imread("lena.png", CV_LOAD_IMAGE_COLOR);
    if (img.empty()){
    cout << "Cannot load image!" << endl;
    return -1;
    }
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", img);
waitKey(0);
return 0;
}