please help-no errors but nor output...

asked 2015-03-24 01:10:55 -0500

sandun gravatar image

updated 2015-03-24 02:11:01 -0500

 //http://opencv-srf.blogspot.com/2013/06/load-display-image.html
//http://opencv-srf.blogspot.com/2013/06/load-display-image.html

#include "opencv2/imgproc/imgproc.hpp"//erosion step ekedi add kala.
#include "opencv2/highgui/highgui.hpp"
//#include "opencv2/imgcodecs.hpp"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using namespace cv;

//http://docs.opencv.org/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html--erosion site eka.
//global variables for erosion;unusable nam delete karanna-dialation ekka conflict vela tiyenna puluvan..
Mat src, erosion_dst;
//for erosion.
int erosion_elem=0;
int erosion_size=0;
int const max_elem=2;
int const max_kernel_size=21;
/*function Headers-(for erosion)*/
void Erosion(int,void* );

/**Function main*/

int main( int, char** argv )
{
    //load image--erosion.
    src=imread(argv[1]);
    if(src.empty()){
        return -1;}
    //create windows-erosion.
    namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
    /// Default start
  Erosion( 0, 0 );

  waitKey(0);
//return 0;//oneda danne na.

 /**simple load image-- from web site.*/

  Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'

if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
          //system("pause"); //wait for a key press
return -1;
}

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

waitKey(0); //wait infinite time for a keypress

     destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

return 0;

}

//erosion function.     //http://docs.opencv.org/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html
void Erosion(int,void*){
int erosion_type=0;
erosion_type = MORPH_RECT;//pahatha dekata venas kara balanna.
//erosion_type = MORPH_CROSS;
//erosion_type = MORPH_ELLIPSE;

Mat element=getStructuringElement(erosion_type,Size(2*erosion_size+1,2*erosion_size+1),Point(erosion_size,erosion_size));
//Apply the Erosion operation.
erode(src,erosion_dst,element);
imshow("Erosion Demo",erosion_dst);
}
edit retag flag offensive close merge delete

Comments

Please don't just dump unformatted code without any explanation!

FooBar gravatar imageFooBar ( 2015-03-24 02:11:58 -0500 )edit

@sandun: Please read http://answers.opencv.org/faq/ before posting your questions. It looks like you dint get any output as you did not specified any argument to your application. argv is empty in your case, so imread fails and hence condition of src.empty satisfies. Put some messages in your code to debug where it break out.

Spark gravatar imageSpark ( 2015-03-24 03:41:13 -0500 )edit

IMHO, you are displaying an empty window (Erosion Demo), then, if you hit a key you'll display the input and then if you hit a key you are closing the window of input image and display the erosion and exit. If you add a waitKey(0) at the end, after the last imshow, isn't it displaying the result?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-03-24 04:07:24 -0500 )edit

Thankx for your kind support.actually i'm very new to opencv and still working to make things know. so sorry for any dismatch or odd here . thankx again for help.

sandun gravatar imagesandun ( 2015-04-07 08:25:16 -0500 )edit

Glad if someone can correct the above error

sandun gravatar imagesandun ( 2015-04-07 10:19:08 -0500 )edit