Ask Your Question
0

Opencv output not matching examples

asked 2017-10-22 22:40:19 -0600

I am trying to do some vertical and horizontal line splitting with the Sobol operator. I was reading this example and I tried it out in my jupyter notebook, but my output was completely different from the example. I literally copied and pasted the code, so I'm puzzled why my output is so different. Any suggestions?

Here is the example:

image description

Here is my output:

edit retag flag offensive close merge delete

Comments

hard to help, without seeing any code.

berak gravatar imageberak ( 2017-10-23 00:45:29 -0600 )edit

Here is my code

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('dave.jpg',0)
laplacian = cv2.Laplacian(img,cv2.CV_64F)
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)

plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray')
plt.title('Original'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray')
plt.title('Laplacian'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray')
plt.title('Sobel X'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray')
plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])

plt.show()
Mitchelld12345 gravatar imageMitchelld12345 ( 2017-10-23 09:11:42 -0600 )edit

I have the same problem with and without jupyter. Image Gradient

David Petretta gravatar imageDavid Petretta ( 2017-12-30 07:25:19 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2017-10-23 03:53:07 -0600

supra56 gravatar image

updated 2017-10-23 03:54:06 -0600

For jupyter notebook, you will have to changed values such as HoughlineS, HoughlinesP, canny, threshold, gaussianBlur, etc. You have to play around with values.

edit flag offensive delete link more

Comments

So this is just related to Jupyter notebook?

Mitchelld12345 gravatar imageMitchelld12345 ( 2017-10-23 09:14:00 -0600 )edit

@Mitchelld12345 I'm using raspberry pi 3, python 3.5 and OpenCV 3.3.0. If I copied from pc to rpi3..it will worked, but sometimes will not work on linux.

supra56 gravatar imagesupra56 ( 2017-10-23 12:02:02 -0600 )edit

I have the exact same problem. I'm using python 2.7 on a fedora-linux, from inside the PyCharm IDE. It's unlikely that the error is caused by Jupyter.
Can anybody provide a version of the sample code that actually reproduces the very nice output image in http://opencv-python-tutroals.readthe...

MartinHvidberg gravatar imageMartinHvidberg ( 2018-03-25 03:35:11 -0600 )edit
1

answered 2017-10-23 09:40:50 -0600

essamzaky gravatar image

I think you can convert image to black and while before executing the laplacian function . note the image is degraded so try to use opencv Adaptive threashould before laplacian Adaptive Threashold

edit flag offensive delete link more
0

answered 2018-08-20 06:25:36 -0600

I did a GaussianBlur on the input image to reduce noise and got a little closer to the results shown in the example.

img = cv.GaussianBlur( img, (5,5), 0 )

image description

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-10-22 22:35:26 -0600

Seen: 651 times

Last updated: Aug 20 '18