Ask Your Question

NabeelKhan's profile - activity

2020-07-13 02:44:59 -0600 received badge  Famous Question (source)
2020-04-07 02:23:49 -0600 received badge  Famous Question (source)
2019-09-13 02:11:17 -0600 received badge  Notable Question (source)
2019-04-24 13:12:35 -0600 received badge  Popular Question (source)
2018-08-09 17:08:04 -0600 received badge  Notable Question (source)
2018-07-03 07:05:24 -0600 received badge  Popular Question (source)
2017-12-13 20:41:46 -0600 received badge  Notable Question (source)
2017-12-13 04:44:09 -0600 received badge  Popular Question (source)
2017-11-11 00:23:12 -0600 received badge  Popular Question (source)
2017-07-28 04:01:21 -0600 received badge  Popular Question (source)
2016-01-27 19:13:41 -0600 commented answer edge corners are not sharp with canny filter

any solution with openCV

2016-01-26 20:55:59 -0600 asked a question edge corners are not sharp with canny filter

Hi,

I am trying to detect edges from an image using Canny filter. I have been able to detect the images but the corners are not very sharp (highlighted in red circles). Surprisingly, the first corner is sharp and not burned out compared to other corners. Why this is happening and how it can be avoided ??

Please have a look at the attached image.

image description

My code:

edges = cv2.Canny(image,0,255)

I have not applied any blurring as it makes the corners worse. Moreover, the change of min and max values for Canny also does not make any difference

2015-08-19 17:14:49 -0600 commented answer contourArea() unit ??

so it basically returns the number of pixels in the object ?? plz correct me if I am wrong

2015-08-19 15:47:27 -0600 asked a question contourArea() unit ??

Hi,

I am using contourArea() to get the area of a binary object

My question: does it return the number of pixels ?? Or if area then what is the unit of it

I need to convert the area into Mm2 and report it

Any help will be really appreciated

Thanks

2015-07-13 21:02:08 -0600 asked a question complement 16 bit mat and then convert it to 8 bit

I have 16 bit openCV Mat. I am looking to complement the MAT and then convert it into 8 bit openCV Mat. I have done it in MATLAB but don't know how to do it in openCV.

My MATLAB code is:

imComplement = imcomplement(image);

img8Bit = im2uint8(imComplement);

where image is 16 bit

2015-07-08 15:16:27 -0600 answered a question sortIdx seems not to work

Normally, sortIdx returns MAT of type ushort. I was trying to create a MAT of type float and display it, which was not working. Now everything works perfectly fine. My new code is :

Mat t = cvCreateMat(3,6,CV_32F);
t.setTo(1);
t.at<float>(0,0)=10;
t.at<float>(1,1)=20;
t.at<float>(2,1)=30;
t.at<float>(1,2)=5;
t.at<float>(2,4)=16;
t.at<float>(0,5)=40;
t.at<float>(0,2)=140;
cout<<t<<"\n";

Mat t1= cvCreateMat(t.rows* t.cols, 1, CV_32F);
t1 = t.reshape(1,t.rows*t.cols);


Mat ind= cvCreateMat(t.rows*t.cols,1,CV_16U);
sortIdx(t1, ind,  CV_SORT_EVERY_COLUMN | CV_SORT_DESCENDING);

for(int i=0;i<ind.rows;i++)
{
    cout<<ind.at<ushort>(i,0)<<"\t\t"<<t1.at<float>(i,0)<<"\n";
}

for(int i=0;i<ind.rows;i++)
{
    int row = ind.at<ushort>(i,0);
    int col = ind.at<ushort>(i,0);
    row = row /t.cols;
    col = col% t.cols;

    cout<<row<<"\t"<<col<<"\n";
}
getchar();
return 0;
2015-07-04 06:36:06 -0600 commented question sortIdx seems not to work

thanks for that ... this means that MAT object (created by any constructor as discussed above) is deleted automatically .... plz correct me If I am wrong

2015-07-03 21:59:05 -0600 commented question sortIdx seems not to work

I am using openCV in big project , where we want the openCV MAT object to be deleted automatically.

I read in documentation that if we declare openCV MAT with cvCreateMat() function then MAT is deleted automatically once u are outside the scope ...

Will it also happen with Mat temp(5,1,CV_32F) ??

2015-07-02 22:48:23 -0600 asked a question sortIdx seems not to work

I am trying to sort elements of 1D mat in descending order. Code seems to work fine in python (openCV) but does not work in C++. In C++, I get zero values as output

My code (C++):

> cv::Mat temp = cvCreateMat(5,
> 1,CV_32F); temp.setTo(10);
> temp.at<float>(2, 0) = 20;
> temp.at<float>(4, 0) = 40; cv::Mat
> ind; cv::sortIdx(temp, ind, CV_SORT_DESCENDING);

Pyhton Code:

     kernel = np.ones((7,1), np.int32)  
    kernel[5]=10    
    p =cv2.sortIdx(kernel, cv2.SORT_DESCENDING+cv2.SORT_EVERY_COLUMN)

My output index array turns out to be zero with C++ code which is strange ... I tried a lot but don't know what's going on

2015-05-16 20:13:17 -0600 asked a question save 16 bit images

I am loading 16 bit image using openCV. Then I do some processing on it and save it back on the disc using imwrite function of openCV. Surprisingly, the image is rescaled between 0-255

On the other hand, if I save image without any processing on the disc using imwrite then image is saved as 16 -bit

What's going on? Do I need to apply some conversion after processing? My code is:

img16Bit = cv2.imread('map.pgm',-1)
imwrite("actualImage.jpg", img16Bit)         # works fine

# does some processing on img16Bit
imwrite('processedImage.jpg', img16Bit)    # image is scaled bw 0-255
2015-05-12 15:25:56 -0600 commented question cubic spline interpolation on contour points

yes, I can apply interpolation in python. Though looking for alternative in C++

2015-05-12 15:25:13 -0600 received badge  Enthusiast
2015-05-12 01:14:53 -0600 received badge  Student (source)
2015-05-11 23:33:32 -0600 commented question cubic spline interpolation on contour points

I also need to preserve the sequence of points for complex objects. After drawing contour, I cannot keep track of it .. Moreover, it's still not smooth (I tired that)

2015-05-11 21:10:08 -0600 commented question cubic spline interpolation on contour points

code is added

2015-05-11 21:09:47 -0600 received badge  Editor (source)
2015-05-11 17:18:33 -0600 asked a question cubic spline interpolation on contour points

I have traced the boundary of an object using openCV as shown in the figure :

image description

I have vectorX and vectorY holding the x-axis and y-axis coordinates of above curve. Th curve looks fine but when we zoom it in we find that the curve is not smooth i.e. jagged:

image description

I require smooth curve before further processing. In MATLAB, we can use CSAPS (Cubic smoothing spline) to smooth such curves and it works pretty well. I am looking to do the same thing either using openCV or some free C++ library. I am looking to get an output like the following (where curve is smoothed by CSAPS function):

image description

Any help will be really appreciated in this regard.

My code:

ret,thresh = cv2.threshold(imgray,50,255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

xSample = np.flipud(contours[0][:,0,0])
ySample = np.flipud(contours[0][:,0,1])

arraySample = np.vstack([xSample, ySample])
arraySample = arraySample.T
plt.figure(2)
plt.plot(arraySample[:,0],  arraySample[:,1], 'ro-')
plt.show()
2015-05-06 20:40:44 -0600 marked best answer tracking boundary using opencv

I am trying to track/ trace boundary points in sequence from the following binary image:image description

I am using OpenCV (python). I am using three ways:

  1. Apply Canny edge detection to detect edge. Problem is how to get the sequence of points? It's work fine but it's very hard to get the sequence of boundary points
  2. Ideal option is to detect contours on the binary image. Because contours return the boundary points in sequence. But openCV contour method is not detecting the boundary as shown in the results. Why is this happening?
  3. Detect contours on the Canny edge. Still some boundary is missed ?? image description

Can anyone help me what's going on with OpenCV contours? Why it is not tracking the complete boundary. I am detecting contours as follows:

contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE ,cv2.CHAIN_APPROX_SIMPLE)

where thresh1 is the binary image

2015-05-06 20:40:43 -0600 commented answer tracking boundary using opencv

yes it works perfectly fine ... thanks a lot

2015-05-06 20:40:19 -0600 received badge  Scholar (source)
2015-05-06 20:40:18 -0600 received badge  Supporter (source)
2015-05-05 20:06:33 -0600 commented answer tracking boundary using opencv

thanks a lot ... will give it a try

2015-05-05 15:28:20 -0600 commented answer tracking boundary using opencv

problem is that I need the boundary points in sequence. Non-zero will fail in some cases especially if object shape is weird such as two folds at any place. I need sequence starting from top to the bottom as boundary is traced. Due to some reason contour is failing ?? I want to know why this is happening ??

2015-05-05 15:26:51 -0600 commented question tracking boundary using opencv

My code is :

seg= cv2.imread(eachImg) # reading binary image blurred= cv2.medianBlur(seg,3) contours, hierarchy = cv2.findContours(blurred,cv2.RETR_TREE ,cv2.CHAIN_APPROX_SIMPLE)