Ask Your Question

cv_new's profile - activity

2018-08-02 07:52:22 -0500 received badge  Notable Question (source)
2018-07-24 04:31:31 -0500 received badge  Famous Question (source)
2018-05-30 15:53:38 -0500 received badge  Famous Question (source)
2018-03-05 05:30:09 -0500 received badge  Popular Question (source)
2017-11-05 18:59:19 -0500 commented answer How to obtain a correct depth map?

Thank you. It works!!

2017-11-05 18:58:57 -0500 marked best answer How to obtain a correct depth map?

I am trying to create a depth map from stereo images, but the generated depth map is only black in color. Could you suggest what should I improve for getting a decent depth map? Thanks.

In my view, the parameters using in the constructor bpm is wrong. How to correct them?

Stereo images Stereo images.jpeg

Depth Map depthMat.jpg

#include <stdio.h>
#include <iostream>
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"

using namespace cv;
using namespace cv::gpu;


int main(int argc, char** argv)
{
    Mat img = imread("C:\\photo\\img0001.jpeg");
    cv::Rect leftROI(0, 0, img.cols/2, img.rows );
    cv::Rect rightROI(img.cols / 2, 0, img.cols/2, img.rows);

    Mat imgLeft = img(leftROI);
    Mat imgRight = img(rightROI);
    Mat depthMat;
    GpuMat disp_gpu, disp_gpu_depth, left_gpu, right_gpu, disp;
    int nD = 10, maxIter = 50;

    StereoBeliefPropagation bpm(nD, maxIter, 4, 25, 0.1f, 100, 1, CV_32F);

    left_gpu.upload(imgLeft);
    right_gpu.upload(imgRight);

    bpm(left_gpu, right_gpu, disp_gpu);

    disp_gpu.download(depthMat);
    imshow("windowDisparity", depthMat);
    imwrite("c:\\photo\\depthMat.jpg", depthMat);
    return 0;
}
2017-11-05 18:58:57 -0500 received badge  Scholar (source)
2017-10-31 20:54:14 -0500 asked a question How to obtain a correct depth map?

How to obtain a correct depth map? I am trying to create a depth map from stereo images, but the generated depth map is

2017-09-28 07:23:42 -0500 received badge  Notable Question (source)
2017-08-03 03:57:39 -0500 received badge  Famous Question (source)
2017-06-23 08:13:09 -0500 received badge  Notable Question (source)
2017-05-26 11:46:12 -0500 received badge  Popular Question (source)
2017-04-17 12:44:49 -0500 received badge  Popular Question (source)
2016-04-22 07:42:50 -0500 received badge  Notable Question (source)
2016-03-22 00:10:21 -0500 commented question How can I package the opencv library into a single jar and then import that to use?

Thank you for the answer.

2016-03-18 05:39:27 -0500 asked a question How can I package the opencv library into a single jar and then import that to use?

In the Ubuntu 12.04 platform, I created a class Foo which used the opencv library, and then I export the whole project into a jar which include all the opencv library through the Eclipse tool. Last but not least, I am going to import that previous jar in order to make good use of a Foo class. How can I do that?

Some suggested the following method, but I am not quite sure.

http://stackoverflow.com/questions/18...

2016-03-08 04:10:54 -0500 asked a question How can I get the coordinates of centers of k-mean clustering?

I am not familiar with the kmeans method.

Core.kmeans(samples32f, k, labels, criteria, 1, Core.KMEANS_PP_CENTERS, centers);

int r = (int)centers.get(label, 2)[0];
int g = (int)centers.get(label, 1)[0];
int b = (int)centers.get(label, 0)[0];

These can provide the information of RGB values of each center. How can I get the coordinates of centers of k-mean clustering?

2016-03-08 02:57:36 -0500 commented answer Color classification

Thanks for your help. They are different now. But when I convert the image to HSV domain for further clustering, the resulting clustered image are quite dirty, how can I split the character better? I am going to do the masking afterwards.

2016-03-07 23:43:22 -0500 commented answer Color classification

I have changed my method to K-means clustering, but I got all the same images at the end.

2016-03-07 20:50:44 -0500 asked a question Color classification

I am goint to find out hsv values of four main colors in a image like this, so that I could get those values.(minH1, minS1, ..., maxS4, maxV4). What would be the best way to make a color clustering?

image description

Scalar lowerA = new Scalar( minH1,minS1,minV1);
Scalar upperA = new Scalar(maxH1,maxS1,maxV1);

Scalar lowerB = new Scalar( minH2,minS2,minV2);
Scalar upperB = new Scalar(maxH2,maxS2,maxV2);

Scalar lowerC = new Scalar( minH3,minS3,minV3);
Scalar upperC = new Scalar(maxH3,maxS3,maxV3);

Scalar lowerD = new Scalar( minH4,minS4,minV4);
Scalar upperD = new Scalar(maxH4,maxS4,maxV4);

The k-mean clustering are not doing quite well in the HSV domain. How could I solve it?

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.TermCriteria;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
//import org.opencv.highgui.Highgui;

public class TestingOpenCV {
    public static void main (String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat img = Imgcodecs.imread("C:\\imagetesting\\defimgGray.jpg");    // 入力画像の取得
        int k = 5;
        Mat hsv = new Mat();
        Mat cropped_hsv = new Mat();
        Imgproc.cvtColor(img, hsv, Imgproc.COLOR_RGB2HSV); 
        List<Mat> channels = new ArrayList<Mat>();
        Core.split(hsv,channels);
        cropped_hsv = channels.get(0);
        List<Mat> temp = new ArrayList<Mat>();
        temp = cluster(hsv, k);
        Mat clusters1 = temp.get(0);
        Mat clusters2 = temp.get(1);
        Mat clusters3 = temp.get(2);
        Mat clusters4 = temp.get(3);
        Mat clusters5 = temp.get(4);

        Imgcodecs.imwrite("C:\\imagetesting\\clusters1.jpg",clusters1);             // 画像をJPG形式で保存
        Imgcodecs.imwrite("C:\\imagetesting\\clusters2.jpg",clusters2);             // 画像をJPG形式で保存
        Imgcodecs.imwrite("C:\\imagetesting\\clusters3.jpg",clusters3);             // 画像をJPG形式で保存
        Imgcodecs.imwrite("C:\\imagetesting\\clusters4.jpg",clusters4);             // 画像をJPG形式で保存
        Imgcodecs.imwrite("C:\\imagetesting\\clusters5.jpg",clusters5);             // 画像をJPG形式で保存

    }
    public static List<Mat> cluster(Mat cutout, int k) {
        Mat samples = cutout.reshape(1, cutout.cols() * cutout.rows());
        Mat samples32f = new Mat();
        samples.convertTo(samples32f, CvType.CV_32F, 1.0 / 255.0);
        Mat labels = new Mat();
        TermCriteria criteria = new TermCriteria(TermCriteria.COUNT, 100, 1);
        Mat centers = new Mat();
        Core.kmeans(samples32f, k, labels, criteria, 1, Core.KMEANS_PP_CENTERS, centers);
        return showClusters(cutout, labels, centers);
    }   

    private static List<Mat> showClusters (Mat cutout, Mat labels, Mat centers) {
        centers.convertTo(centers, CvType.CV_8UC1, 255.0);
        centers.reshape(3);
        List<Mat> clusters = new ArrayList<Mat>();

        for(int i = 0; i < centers.rows(); i++) {           
            //clusters.add(Mat.zeros(cutout.size(), cutout.type()));
            Mat light = new Mat(cutout.size(),cutout.type(), new Scalar(255,255,255));
            clusters.add(light);
        }

        int rows = 0;
        for(int y = 0; y < cutout.rows(); y++) {
            for(int x = 0; x < cutout.cols(); x++) {

                int label = (int)labels.get(rows, 0)[0];
                int r = (int)centers.get(label, 2)[0];
                int g = (int)centers.get(label, 1)[0];
                int b = (int)centers.get(label, 0)[0];

                Mat tempMat = new Mat(); 
                tempMat = clusters.get(label);
                tempMat.put(y, x, b, g, r);
                clusters.set(label,tempMat);                    
                rows++;
            }
        }
        return clusters;
    }
}
2016-03-04 00:48:52 -0500 commented answer How to draw a line on Mat?

Thank you.

2016-03-04 00:44:42 -0500 asked a question How to draw a line on Mat?

I find the Core.line doesn't work in opencv 3.1 for java verison. What should it be? Thanks.

Mat Img = new Mat();
Point pt1 = new Point(x1, y1);
Point pt2 = new Point(x2, y2);
Core.line(Img, pt1, pt2, new Scalar(0,255,0), 3);
2016-03-03 00:58:17 -0500 commented question Is there any special in the fastNlMeansDenoising function?

This is my mistake. Though the parameters set are the same, the denoising effect of java one is not good as the C++ one

2016-03-01 22:53:52 -0500 asked a question Is there any special in the fastNlMeansDenoising function?

I find that the fastNlMeansDenoising function in C++ verison and java verison are different in results. The java verison does not work pretty well. Why does it cause like this?

C++:
fastNlMeansDenoising(mat1, mat2, 3, 7, 21);
Java:
Photo.fastNlMeansDenoising(mat1, mat2, 3, 7, 21);
2016-02-29 21:36:21 -0500 asked a question Why the pixel values are different from those in the original image?

I used the following java opencv code to obtain the pixel value, but they are different from what I saw in IrfanView.

double[] central;
central = mat.get(y, x);

The pixel value originally from (255, 0, 0) turns to (67,64,73).

2016-02-29 19:27:06 -0500 commented question How can I change the following functions to opencv in java verison

I found it with Imgproc.copyMakeBorder(source,destination,top,bottom,left,right,borderType).

2016-02-29 02:47:51 -0500 commented question How can I change the following functions to opencv in java verison

It is in C++ verison. I want to know how to change this "src.copyTo(padded(Rect(padding, padding, src.cols, src.rows)));" to that of java verison. Thanks in advance.

2016-02-29 02:05:11 -0500 asked a question How can I change the following functions to opencv in java verison
Mat src = imread(argv[1], CV_LOAD_IMAGE_COLOR); 
Mat padded; 
int padding = 5;
padded.create(src.rows + 2 * padding, src.cols + 2 * padding, src.type());
padded.setTo(Scalar::all(255));
src.copyTo(padded(Rect(padding, padding, src.cols, src.rows)));
2016-01-27 04:16:08 -0500 commented question Face detection is very slow

Skip some frames to make a test :¬)