How to find a segment location after applying PyrMeanShiftFiltering.

asked 2016-11-12 03:38:18 -0500

adnandani gravatar image

updated 2016-11-12 21:29:59 -0500

I am using following code to differentiate between a sky blue region (required region) in my image C:\fakepath\input image.jpg

and the background. I have applied PyrMeanShiftFiltering function to do segmentation of the image. After applying code the result

C:\fakepath\result.jpg

image have successfully segmented sky blue section but now i want to know the location of this sky blue region (mid point). Can any one help me how i can know the coordinates of this blue region in my image after doing this image segmentation.

#include "cv.h"
#include "highgui.h"
#include "math.h"
#include <iostream.h>


int main(int argc, char** argv)
{
IplImage* output_image;

    IplImage* image = cvLoadImage("31.jpg",CV_LOAD_IMAGE_COLOR);
  CvMemStorage* storage = cvCreateMemStorage(0);
        cvNamedWindow( "origional image", 1 );
        cvShowImage( "origional image", image);
        cvWaitKey(0);

    IplImage *filtered = cvCreateImage(cvGetSize(image),image->depth,image->nChannels);

        cvCopy(image,filtered,NULL);

  int level = 3;
  int spatial_radius = 40;
  int color_radius  = 40;

  filtered->width &= -(1<<level);
  filtered->height &= -(1<<level);

  cvPyrMeanShiftFiltering(filtered, filtered,spatial_radius,color_radius,level);
  cvNamedWindow( "fourth", 1 );
        cvShowImage( "fourth", filtered);
        cvWaitKey(0);

   return 0;
}
edit retag flag offensive close merge delete

Comments

hello, noob, --

problem #1 is, that you're trying to use the deprecated c-api. opencv moved away from that in 2010 already, and most of it is no more maintained.

before trying to improve anything here, - please try to rewrite it, using c++, cv::Mat and cv::pyrMeanShiftFiltering

berak gravatar imageberak ( 2016-11-12 03:51:24 -0500 )edit

Actually, i am working on a project that is totally based on visual c++ 6.0 and opencv 1.0. I cannot change version because project is very complex and i would need to make complete new project if i will change version. I have googled my query but all help is related to new versions. Please help me is there any way i can achieve my goal while using these versions ?

adnandani gravatar imageadnandani ( 2016-11-12 03:58:04 -0500 )edit

inRange() might be useful ( maybe needs conversion to hsv before)

berak gravatar imageberak ( 2016-11-13 03:41:13 -0500 )edit