Python cv2.CV_64F Examples

The following are 30 code examples of cv2.CV_64F(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: BlurDetection.py    From python-- with GNU General Public License v3.0 10 votes vote down vote up
def _lapulaseDetection(self, imgName):
        """
        :param strdir: 文件所在的目录
        :param name: 文件名称
        :return: 检测模糊后的分数
        """
        # step1: 预处理
        img2gray, reImg = self.preImgOps(imgName)
        # step2: laplacian算子 获取评分
        resLap = cv2.Laplacian(img2gray, cv2.CV_64F)
        score = resLap.var()
        print("Laplacian %s score of given image is %s", str(score))
        # strp3: 绘制图片并保存  不应该写在这里  抽象出来   这是共有的部分
        newImg = self._drawImgFonts(reImg, str(score))
        newDir = self.strDir + "/_lapulaseDetection_/"
        if not os.path.exists(newDir):
            os.makedirs(newDir)
        newPath = newDir + imgName
        # 显示
        cv2.imwrite(newPath, newImg)  # 保存图片
        cv2.imshow(imgName, newImg)
        cv2.waitKey(0)

        # step3: 返回分数
        return score 
Example #2
Source File: lane.py    From Vehicle-and-Speed-Identification with MIT License 6 votes vote down vote up
def dir_threshold(img, sobel_kernel=3, thresh=(0, np.pi/2)):
    """ threshold according to the direction of the gradient
    :param img:
    :param sobel_kernel:
    :param thresh:
    :return:
    """

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the gradient in x and y separately
    sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
    sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)

    # 3) Take the absolute value of the x and y gradients
    # 4) Use np.arctan2(abs_sobely, abs_sobelx) to calculate the direction of the gradient
    absgraddir = np.arctan2(np.absolute(sobely), np.absolute(sobelx))

    # 5) Create a binary mask where direction thresholds are met
    binary_output =  np.zeros_like(absgraddir)
    binary_output[(absgraddir >= thresh[0]) & (absgraddir <= thresh[1])] = 1

    return binary_output 
Example #3
Source File: lane.py    From vehicle-detection with GNU General Public License v3.0 6 votes vote down vote up
def abs_sobel_thresh(img, orient='x', sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the derivative in x or y given orient = 'x' or 'y'
    # 3) Take the absolute value of the derivative or gradient
    if orient == 'x':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel))
    if orient == 'y':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel))

    # 4) Scale to 8-bit (0 - 255) then convert to type = np.uint8
    scaled_sobel = np.uint8(255.*abs_sobel/np.max(abs_sobel))

    # 5) Create a mask of 1's where the scaled gradient magnitude
    # is > thresh_min and < thresh_max
    binary_output = np.zeros_like(scaled_sobel)
    binary_output[(scaled_sobel >= thresh[0]) & (scaled_sobel <= thresh[1])] = 1

    return binary_output 
Example #4
Source File: chessboard.py    From cvcalib with Apache License 2.0 6 votes vote down vote up
def compute_inital_corner_likelihood(image):
    likelihoods = []
    for prototype in ck.CORNER_KERNEL_PROTOTYPES:
        filter_responses = [cv2.filter2D(image, ddepth=cv2.CV_64F, kernel=kernel) for kernel in prototype]
        fA, fB, fC, fD = filter_responses
        mean_response = (fA + fB + fC + fD) / 4.
        minAB = np.minimum(fA, fB)
        minCD = np.minimum(fC, fD)
        diff1 = minAB - mean_response
        diff2 = minCD - mean_response
        # For an ideal corner, the response of {A,B} should be greater than the mean response of {A,B,C,D},
        # while the response of {C,D} should be smaller, and vice versa for flipped corners.
        likelihood1 = np.minimum(diff1, -diff2)
        likelihood2 = np.minimum(-diff1, diff2)  # flipped case
        likelihoods.append(likelihood1)
        likelihoods.append(likelihood2)
    corner_likelihood = np.max(likelihoods, axis=0)
    return corner_likelihood 
Example #5
Source File: process.py    From lowpolypy with MIT License 6 votes vote down vote up
def get_laplace_points(self, image: np.ndarray, num_points=500) -> np.ndarray:
        if num_points <= 0:
            return np.zeros((0, 2), dtype=np.uint8)
        image = cv2.GaussianBlur(image, (15, 15), 0)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = np.uint8(np.absolute(cv2.Laplacian(image, cv2.CV_64F, 19)))
        image = cv2.GaussianBlur(image, (15, 15), 0)
        image = (image * (255 / image.max())).astype(np.uint8)
        image = image.astype(np.float32) / image.sum()
        if self.options['visualize_laplace']:
            self.visualize_image(image, 'laplace')
        weights = np.ravel(image)
        coordinates = np.arange(0, weights.size, dtype=np.uint32)
        choices = np.random.choice(coordinates, size=num_points, replace=False, p=weights)
        raw_points = np.unravel_index(choices, image.shape)
        points = np.stack(raw_points, axis=-1)[..., ::-1]
        return points 
Example #6
Source File: reduce_image_by_seam_carving.py    From OpenCV-3-x-with-Python-By-Example with MIT License 6 votes vote down vote up
def compute_energy_matrix(img): 
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
 
    # Compute X derivative of the image 
    sobel_x = cv2.Sobel(gray,cv2.CV_64F, 1, 0, ksize=3) 
 
    # Compute Y derivative of the image 
    sobel_y = cv2.Sobel(gray,cv2.CV_64F, 0, 1, ksize=3) 
 
    abs_sobel_x = cv2.convertScaleAbs(sobel_x) 
    abs_sobel_y = cv2.convertScaleAbs(sobel_y) 
 
    # Return weighted summation of the two images i.e. 0.5*X + 0.5*Y 
    return cv2.addWeighted(abs_sobel_x, 0.5, abs_sobel_y, 0.5, 0) 
 
# Find vertical seam in the input image 
Example #7
Source File: plant_features.py    From bonnet with GNU General Public License v3.0 6 votes vote down vote up
def gradients(mask, direction='x'):
  '''
    Get gradients using sobel operator
  '''
  mask = cv2.GaussianBlur(mask, (5, 5), 0)

  if direction == 'x':
    # grad x
    sobel = cv2.Sobel(mask, cv2.CV_64F, 1, 0, ksize=7)
  elif direction == 'y':
    # grad y
    sobel = cv2.Sobel(mask, cv2.CV_64F, 0, 1, ksize=7)
  else:
    print("Invalid gradient direction. Must be x or y")
    quit()

  # sobel = np.absolute(sobel)
  sobel = contrast_stretch(sobel)   # expand contrast
  sobel = np.uint8(sobel)

  return sobel 
Example #8
Source File: plant_features.py    From bonnet with GNU General Public License v3.0 6 votes vote down vote up
def laplacian(mask):
  '''
    Get 2nd order gradients using the Laplacian
  '''

  # blur
  mask = cv2.GaussianBlur(mask, (5, 5), 0)

  # edges with laplacian
  laplacian = cv2.Laplacian(mask, cv2.CV_64F, 5)

  # stretch
  laplacian = contrast_stretch(laplacian)

  # cast
  laplacian = np.uint8(laplacian)

  return laplacian 
Example #9
Source File: artistic.py    From imgaug with MIT License 6 votes vote down vote up
def _find_edges_laplacian(image, edge_multiplier, from_colorspace):
    image_gray = colorlib.change_colorspace_(np.copy(image),
                                             to_colorspace=colorlib.CSPACE_GRAY,
                                             from_colorspace=from_colorspace)
    image_gray = image_gray[..., 0]
    edges_f = cv2.Laplacian(_normalize_cv2_input_arr_(image_gray / 255.0),
                            cv2.CV_64F)
    edges_f = np.abs(edges_f)
    edges_f = edges_f ** 2
    vmax = np.percentile(edges_f, min(int(90 * (1/edge_multiplier)), 99))
    edges_f = np.clip(edges_f, 0.0, vmax) / vmax

    edges_uint8 = np.clip(np.round(edges_f * 255), 0, 255.0).astype(np.uint8)
    edges_uint8 = _blur_median(edges_uint8, 3)
    edges_uint8 = _threshold(edges_uint8, 50)
    return edges_uint8


# Added in 0.4.0. 
Example #10
Source File: FocusStack.py    From focusstack with Apache License 2.0 6 votes vote down vote up
def doLap(image):

    # YOU SHOULD TUNE THESE VALUES TO SUIT YOUR NEEDS
    kernel_size = 5         # Size of the laplacian window
    blur_size = 5           # How big of a kernal to use for the gaussian blur
                            # Generally, keeping these two values the same or very close works well
                            # Also, odd numbers, please...

    blurred = cv2.GaussianBlur(image, (blur_size,blur_size), 0)
    return cv2.Laplacian(blurred, cv2.CV_64F, ksize=kernel_size)

#
#   This routine finds the points of best focus in all images and produces a merged result...
# 
Example #11
Source File: lane.py    From Vehicle-and-Speed-Identification with MIT License 6 votes vote down vote up
def abs_sobel_thresh(img, orient='x', sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the derivative in x or y given orient = 'x' or 'y'
    # 3) Take the absolute value of the derivative or gradient
    if orient == 'x':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel))
    if orient == 'y':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel))

    # 4) Scale to 8-bit (0 - 255) then convert to type = np.uint8
    scaled_sobel = np.uint8(255.*abs_sobel/np.max(abs_sobel))

    # 5) Create a mask of 1's where the scaled gradient magnitude
    # is > thresh_min and < thresh_max
    binary_output = np.zeros_like(scaled_sobel)
    binary_output[(scaled_sobel >= thresh[0]) & (scaled_sobel <= thresh[1])] = 1

    return binary_output 
Example #12
Source File: lane.py    From Vehicle-and-Speed-Identification with MIT License 6 votes vote down vote up
def mag_thresh(img, sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the gradient in x and y separately
    sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
    sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)

    # 3) Calculate the magnitude
    gradmag = np.sqrt(sobelx**2 + sobely**2)

    # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8
    scale_factor = np.max(gradmag)/255
    gradmag = (gradmag/scale_factor).astype(np.uint8)

    # 5) Create a binary mask where mag thresholds are met
    binary_output = np.zeros_like(gradmag)
    binary_output[(gradmag >= thresh[0]) & (gradmag <= thresh[1])] = 1

    return binary_output 
Example #13
Source File: lane.py    From vehicle-detection with GNU General Public License v3.0 6 votes vote down vote up
def mag_thresh(img, sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the gradient in x and y separately
    sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
    sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)

    # 3) Calculate the magnitude
    gradmag = np.sqrt(sobelx**2 + sobely**2)

    # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8
    scale_factor = np.max(gradmag)/255
    gradmag = (gradmag/scale_factor).astype(np.uint8)

    # 5) Create a binary mask where mag thresholds are met
    binary_output = np.zeros_like(gradmag)
    binary_output[(gradmag >= thresh[0]) & (gradmag <= thresh[1])] = 1

    return binary_output 
Example #14
Source File: swt.py    From StrokeWidthTransform with MIT License 6 votes vote down vote up
def _create_derivative(cls, filepath):
        img = cv2.imread(filepath,0)
        edges = cv2.Canny(img, 175, 320, apertureSize=3)
        # Create gradient map using Sobel
        sobelx64f = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=-1)
        sobely64f = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=-1)

        theta = np.arctan2(sobely64f, sobelx64f)
        if diagnostics:
            cv2.imwrite('edges.jpg',edges)
            cv2.imwrite('sobelx64f.jpg', np.absolute(sobelx64f))
            cv2.imwrite('sobely64f.jpg', np.absolute(sobely64f))
            # amplify theta for visual inspection
            theta_visible = (theta + np.pi)*255/(2*np.pi)
            cv2.imwrite('theta.jpg', theta_visible)
        return (edges, sobelx64f, sobely64f, theta) 
Example #15
Source File: OpenCV_var.py    From Image-Blur-Detection with GNU General Public License v3.0 6 votes vote down vote up
def variance_of_laplacian(image):
	# compute the Laplacian of the image and then return the focus
	# measure, which is simply the variance of the Laplacian
	return cv2.Laplacian(image, cv2.CV_64F).var()



# In[ ]:



# In[ ]:


#accuracy_score(y, y_pred)


# In[4]: 
Example #16
Source File: find_best_quality_images.py    From ALPR_System with Apache License 2.0 6 votes vote down vote up
def get_best_images(plate_images, num_img_return):
    """
    Get the top num_img_return quality images (with the least blur).
    Laplacian function returns a value which indicates how blur the image is.
    The lower the value, the more blur the image have
    """

    # first, pick the image with the largest area because the bigger the image, the bigger the characters on the plate
    if len(plate_images) > (num_img_return + 2):
        plate_images = sorted(plate_images, key=lambda x : x[0].shape[0]*x[0].shape[1], reverse=True)[:(num_img_return+2)]

    # secondly, pick the images with the least blur
    if len(plate_images) > num_img_return:
        plate_images = sorted(plate_images, key=lambda img : cv2.Laplacian(img[0], cv2.CV_64F).var(), reverse=True)[:num_img_return]
        # img[0] because plate_images = [plate image, char on plate]
    return plate_images 
Example #17
Source File: lane.py    From driving-lane-departure-warning with GNU General Public License v3.0 6 votes vote down vote up
def abs_sobel_thresh(img, orient='x', sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the derivative in x or y given orient = 'x' or 'y'
    # 3) Take the absolute value of the derivative or gradient
    if orient == 'x':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel))
    if orient == 'y':
        abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel))

    # 4) Scale to 8-bit (0 - 255) then convert to type = np.uint8
    scaled_sobel = np.uint8(255.*abs_sobel/np.max(abs_sobel))

    # 5) Create a mask of 1's where the scaled gradient magnitude
    # is > thresh_min and < thresh_max
    binary_output = np.zeros_like(scaled_sobel)
    binary_output[(scaled_sobel >= thresh[0]) & (scaled_sobel <= thresh[1])] = 1

    return binary_output 
Example #18
Source File: lane.py    From driving-lane-departure-warning with GNU General Public License v3.0 6 votes vote down vote up
def mag_thresh(img, sobel_kernel=3, thresh=(0, 255)):

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the gradient in x and y separately
    sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
    sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)

    # 3) Calculate the magnitude
    gradmag = np.sqrt(sobelx**2 + sobely**2)

    # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8
    scale_factor = np.max(gradmag)/255
    gradmag = (gradmag/scale_factor).astype(np.uint8)

    # 5) Create a binary mask where mag thresholds are met
    binary_output = np.zeros_like(gradmag)
    binary_output[(gradmag >= thresh[0]) & (gradmag <= thresh[1])] = 1

    return binary_output 
Example #19
Source File: image_process.py    From Advanced_Lane_Lines with MIT License 6 votes vote down vote up
def color_grid_thresh(img, s_thresh=(170,255), sx_thresh=(20, 100)):
	img = np.copy(img)
	# Convert to HLS color space and separate the V channel
	hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)
	l_channel = hls[:,:,1]
	s_channel = hls[:,:,2]
	# Sobel x
	sobelx = cv2.Sobel(l_channel, cv2.CV_64F, 1, 0) # Take the derivateive in x
	abs_sobelx = np.absolute(sobelx) # Absolute x derivateive to accentuate lines
	scaled_sobel = np.uint8(255*abs_sobelx/np.max(abs_sobelx))

	# Threshold x gradient
	sxbinary = np.zeros_like(scaled_sobel)
	sxbinary[(scaled_sobel >= sx_thresh[0]) & (scaled_sobel <= sx_thresh[1])] = 1

	# Threshold color channel
	s_binary = np.zeros_like(s_channel)
	s_binary[(s_channel >= s_thresh[0]) & (s_channel <= s_thresh[1])] = 1

	# combine the two binary
	binary = sxbinary | s_binary

	# Stack each channel (for visual check the pixal sourse)
	# color_binary = np.dstack((np.zeros_like(sxbinary), sxbinary,s_binary)) * 255
	return binary 
Example #20
Source File: image.py    From ai-smarthome with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def process(self):
        if self.input_data[0] is not None:
            image = self.get(0)
            if isinstance(image, ImageData):
                img = cv2.GaussianBlur(image.image, (3,3), 0)
                sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize = 5)
                self.set_output(0, ImageData(sobelx, image.timestamp))
            return True 
Example #21
Source File: 03_image_derivatives.py    From Practical-Computer-Vision with MIT License 5 votes vote down vote up
def main():
    # read an image 
    img = cv2.imread('../figures/building_crop.jpg')
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    
    
    # sobel 
    x_sobel = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
    y_sobel = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)

    # laplacian
    lapl = cv2.Laplacian(img,cv2.CV_64F, ksize=5)

    # gaussian blur
    blur = cv2.GaussianBlur(img,(5,5),0)
    # laplacian of gaussian
    log = cv2.Laplacian(blur,cv2.CV_64F, ksize=5)
    
    # res = np.hstack([img, x_sobel, y_sobel])
    # plt.imshow(res, cmap='gray')
    # plt.axis('off')
    # plt.show()
    # lapl = np.asarray(lapl, dtype= np.uint)
    # Do plot
    plot_cv_img(img, lapl, log) 
Example #22
Source File: lane.py    From driving-lane-departure-warning with GNU General Public License v3.0 5 votes vote down vote up
def dir_threshold(img, sobel_kernel=3, thresh=(0, np.pi/2)):
    """ threshold according to the direction of the gradient

    :param img:
    :param sobel_kernel:
    :param thresh:
    :return:
    """

    # Apply the following steps to img
    # 1) Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    # 2) Take the gradient in x and y separately
    sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
    sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)

    # 3) Take the absolute value of the x and y gradients
    # 4) Use np.arctan2(abs_sobely, abs_sobelx) to calculate the direction of the gradient
    absgraddir = np.arctan2(np.absolute(sobely), np.absolute(sobelx))

    # 5) Create a binary mask where direction thresholds are met
    binary_output =  np.zeros_like(absgraddir)
    binary_output[(absgraddir >= thresh[0]) & (absgraddir <= thresh[1])] = 1

    return binary_output 
Example #23
Source File: opencv_py.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def edgeDetection(inputImg_edge):    
    imgEdge=cv2.imread(inputImg_edge,cv2.IMREAD_GRAYSCALE)  #读取图像
    sobelHorizontal=cv2.Sobel(imgEdge,cv2.CV_64F,1,0,ksize=5) #索贝尔滤波器Sobel filter,横向。参数解释通过help(cv2.Sobel)查看
    """
    help(cv2.Sobel)
    Help on built-in function Sobel:
    .   @param src input image. 输入待处理的图像
    .   @param dst output image of the same size and the same number of channels as src . 输出图像,同大小,同通道数
    .   @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of.  8-bit input images it will result in truncated derivatives. 
    图像深度,-1时与原图像深度同,目标图像的深度必须大于等于原图像深度。避免truncated derivatives而设置cv2.CV_64F数据类型
    .   @param dx order of the derivative x. x方向求导阶数,0表示这个方向没有求导,一般为0,1,2
    .   @param dy order of the derivative y. y方向求导阶数,同上
    .   @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. 算子大小,必须为1、3、5、7
    .   @param scale optional scale factor for the computed derivative values; by default, no scaling is. applied (see cv::getDerivKernels for details).
    缩放导数的比例常数,默认情况五伸缩系数
    .   @param delta optional delta value that is added to the results prior to storing them in dst.
    可选增量,默认情况无额外值加到dst中
    .   @param borderType pixel extrapolation method, see cv::BorderTypes 图像边界模式
    .   @sa  Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar      
    """
    sobelVertical=cv2.Sobel(imgEdge,cv2.CV_64F,0,1,ksize=5) #索贝尔滤波器Sobel filter,纵向
    laplacian=cv2.Laplacian(imgEdge,cv2.CV_64F) #拉普拉斯边检测器,Laplacian edge detector
    canny=cv2.Canny(imgEdge,50,240) #Canny边检测器Canny edge detector
    
#    print(imgEdge)
    cv2.namedWindow('img')
#    cv2.imshow('original',imgEdge)
#    cv2.imshow('sobel horizontal',sobelHorizontal) #输出显示图像
#    cv2.imwrite(os.path.join(rootDirectory,'sobel horizontal.jpg'),sobelHorizontal)
#    cv2.imshow('sobel vertical',sobelVertical)    
#    cv2.imwrite(os.path.join(rootDirectory,'sobel vertical.jpg'),sobelVertical)
    cv2.imshow('laplacian',laplacian)
    cv2.imwrite(os.path.join(rootDirectory,'laplacian.jpg'),laplacian)
#    cv2.imshow('canny',canny)
#    cv2.imwrite(os.path.join(rootDirectory,'canny.jpg'),canny)
    cv2.waitKey()

#检测棱角 
Example #24
Source File: image.py    From perception with Apache License 2.0 5 votes vote down vote up
def normal_cloud_im(self, ksize=3):
        """Generate a NormalCloudImage from the PointCloudImage using Sobel filtering.

        Parameters
        ----------
        ksize : int
            Size of the kernel to use for derivative computation

        Returns
        -------
        :obj:`NormalCloudImage`
            The corresponding NormalCloudImage.
        """
        # compute direction via cross product of derivatives
        gy = cv2.Sobel(self.data, cv2.CV_64F, 1, 0, ksize=ksize)
        gx = cv2.Sobel(self.data, cv2.CV_64F, 0, 1, ksize=ksize)
        gx_data = gx.reshape(self.height * self.width, 3)
        gy_data = gy.reshape(self.height * self.width, 3)
        pc_grads = np.cross(gx_data, gy_data)  # default to point toward camera

        # normalize
        pc_grad_norms = np.linalg.norm(pc_grads, axis=1)
        pc_grads[pc_grad_norms > 0] = pc_grads[pc_grad_norms > 0] / np.tile(pc_grad_norms[pc_grad_norms > 0, np.newaxis], [1, 3])
        pc_grads[pc_grad_norms == 0.0] = np.array([0,0,-1.0]) # zero norm means pointing toward camera

        # reshape
        normal_im_data = pc_grads.reshape(self.height, self.width, 3)

        # preserve zeros
        zero_px = self.zero_pixels()
        normal_im_data[zero_px[:,0], zero_px[:,1], :] = np.zeros(3)
        
        return NormalCloudImage(normal_im_data, frame=self.frame) 
Example #25
Source File: OpenCV_max.py    From Image-Blur-Detection with GNU General Public License v3.0 5 votes vote down vote up
def variance_of_laplacian(image):
	return cv2.Laplacian(image, cv2.CV_64F).var() 
Example #26
Source File: detect_focus2.py    From pi-tracking-telescope with MIT License 5 votes vote down vote up
def variance_of_laplacian(image):
	# compute the Laplacian of the image and then return the focus
	# measure, which is simply the variance of the Laplacian
	return cv2.Laplacian(image, cv2.CV_64F).var() 
Example #27
Source File: focus.py    From pi-tracking-telescope with MIT License 5 votes vote down vote up
def variance_of_laplacian(self, image):
        # compute the Laplacian of the image and then return the focus
        # measure, which is simply the variance of the Laplacian
        return cv2.Laplacian(image, cv2.CV_64F).var() 
Example #28
Source File: view-mongo-images.py    From smart-zoneminder with MIT License 5 votes vote down vote up
def variance_of_laplacian(image):
    # compute the Laplacian of the image and then return the focus
    # measure, which is simply the variance of the Laplacian
    return cv2.Laplacian(image, cv2.CV_64F).var() 
Example #29
Source File: face_detect_server.py    From smart-zoneminder with MIT License 5 votes vote down vote up
def variance_of_laplacian(image):
	# compute the Laplacian of the image and then return the focus
	# measure, which is simply the variance of the Laplacian
	return cv2.Laplacian(image, cv2.CV_64F).var() 
Example #30
Source File: main_2.8-12.py    From motorized_zoom_lens with GNU General Public License v3.0 5 votes vote down vote up
def get_blur(frame, scale):
    frame = cv2.resize(frame, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    fm = cv2.Laplacian(gray, cv2.CV_64F).var()
    return fm