Ask Your Question

zvonimirb's profile - activity

2016-02-16 12:21:34 -0600 asked a question gpu::meanShiftSegmentation - Parameters?

I've been trying to use gpu::meanShiftSegmentation to segment an image into a small number of clusters. My end goal of this would be to get results similar to this matlab code so i could use the OutputMat to find objects that have HUE and SATURATION values that stand out from the rest.

Currently, i'm working on a test image of 240x320px, and trying some of the following parameters:

gpu::meanShiftSegmentation(InputMat, OutputMat, 80, 80, 3)

TermCriteria criteria(CV_TERMCRIT_EPS, 0, 0.8)
gpu::meanShiftSegmentation(InputMat, OutputMat, 80, 80, 3, criteria)

But the number of different segments I am getting in the result image is way to high for such a small input image, 1000+ different segments meaning 1000+ different clusters. The problem is that I don't really understand how the parameters work so I am unable to tweak them to get the results I am looking for.

Can anyone help me understand how "Spatial window radius", "Color window radius" and "criteria" work? I understand that larger numbers give a smaller number of segments, but I'm unable to get a small enough number of clusters (5-6 for this image) without losing my region of interest.

2016-02-10 05:01:54 -0600 answered a question cuda::meanShiftSegmentation - Assertion Failed Error

Can I bump this? Still can't figure out the problem :(

2016-02-09 05:24:55 -0600 received badge  Enthusiast
2016-02-09 05:24:55 -0600 received badge  Enthusiast
2016-02-06 12:23:56 -0600 asked a question cuda::meanShiftSegmentation - Assertion Failed Error

Hi. I'm new to using CUDA with OpenCV so this might be a very simple error but I'm kinda stuck. My code is the following:

#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <stdio.h>
#include <omp.h>
#include <string>
using namespace cv;

int main( int argc, char** argv )
{
Mat pictureBGR;
Mat pictureSegment;
cuda::GpuMat bgr;
cuda::GpuMat convertedBgr;
cuda::GpuMat dstBgr;

std::cout << cuda::getCudaEnabledDeviceCount() << std::endl;
pictureBGR = imread("2.jpg"); //unos slike za pretragu
if(!pictureBGR.data)
{
    std::cout << "Gre\u0161ka pri u\u010ditavanju slike!" << std::endl;
    return -1;
}

bgr.upload(pictureBGR);
cuda::cvtColor(bgr, convertedBgr, CV_BGR2BGRA);

TermCriteria criteria(CV_TERMCRIT_EPS, 0, 0.08);
cuda::meanShiftSegmentation(convertedBgr, dstBgr, 20, 20, 3, criteria);
dstBgr.download(pictureSegment);

namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", pictureSegment);
waitKey(0);
    return 0;
}

And i'm getting the following error:

Assertion failed (src.type() == CV_8UC4) in meanShiftSegmentation, file /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp, line 229
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp:229: error: (-215) src.type() == CV_8UC4 in function meanShiftSegmentation

I understand that the meanShiftSegmentation only takes GpuMat of type 8UC4, but I am still to find a solution to convert it. Any ideas?

std::cout << cuda::getCudaEnabledDeviceCount() << std::endl; returns 1 btw.

2016-01-12 07:57:50 -0600 commented answer How to get OpenCV to store HSV in Matlab notation [0-1]?

The latest edit should probably work. I did it like this though:

Mat pictureBGR;

    pictureBGR = imread("slika1.jpg", CV_LOAD_IMAGE_COLOR); 

    namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
    imshow( "Display Image", pictureBGR );

    Mat pictureHSV;
    cvtColor(pictureBGR, pictureHSV, COLOR_BGR2HSV);

    int size [2] = {pictureHSV.rows, pictureHSV.cols}; 
    std::cout << size[0] << " x " << size[1] <<std::endl;

    std::vector<Mat> pictureH_S_V;
    split(pictureHSV, pictureH_S_V); //razdvajamo HSV u tri kanala, H, S i V

    pictureH_S_V[0].convertTo(pictureH_S_V[0], CV_32FC3, 1.0/179.0); 
    pictureH_S_V[1].convertTo(pictureH_S_V[1], CV_32FC3, 1.0/255.0);

Thanks.

2016-01-12 07:57:23 -0600 received badge  Scholar (source)
2016-01-11 06:04:44 -0600 commented answer How to get OpenCV to store HSV in Matlab notation [0-1]?

Yes, it didn't make any difference to the output.

2016-01-11 03:50:31 -0600 commented answer How to get OpenCV to store HSV in Matlab notation [0-1]?

@berak @Balaji R This still didn't solve my problem, as Hue still appears to be in the 0-180 range. Saturation and Value seem fine. This is my code and output.

Mat pictureBGR;

    pictureBGR = imread("picture1.jpg", CV_LOAD_IMAGE_COLOR); 

    Mat pictureBGR_32;
    pictureBGR.convertTo(pictureBGR_32, CV_32FC3, 1.0/255.0);

    Mat pictureHSV;
    cvtColor(pictureBGR_32, pictureHSV, COLOR_BGR2HSV);

    std::cout << "Hue: "<< pictureHSV.at<float>(0,0) << std::endl;
    std::cout << "Saturation: "<< pictureHSV.at<float>(0,1) << std::endl;
    std::cout << "Value:"<< pictureHSV.at<float>(0,2) << std::endl;

Output:

Hue: 30
Saturation: 0.318182
Value:0.517647

Do you have any ideas why?

2016-01-08 06:35:38 -0600 received badge  Supporter (source)
2016-01-08 06:35:34 -0600 commented answer How to get OpenCV to store HSV in Matlab notation [0-1]?

I don't really understand how to include the above mentioned line in my code, just copy pasting gives me errors. Could you write the whole convertTO line?

2016-01-08 05:59:43 -0600 received badge  Editor (source)
2016-01-08 05:56:07 -0600 received badge  Student (source)
2016-01-08 05:51:22 -0600 asked a question How to get OpenCV to store HSV in Matlab notation [0-1]?

I am working on transferring a working Matlab project to C++/OpenCV, but I'm encountering a problem while converting from BGR to HSV, since the project is intended to work with small numbers that Matlab uses to store HSV values.

If i just do a normalization to the HSV matrix (Hue/179, Saturation/255, Value/255) I will lose a part of data that could be important in the image recognition later on.

Is there a better way to convert from BGR - HSV without losing part of the data? Has anyone encountered this problem? What is the most efficient way solve to it?

Thanks

Zvonimir