Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

np.zeros() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.zeros method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?

np.zeros() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.zeros np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?

np.zeros() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?

np.zeros() np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?image description

np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?image description

import cv2 as cv import numpy as np

def nothing(x): pass

img = cv.imread('sudoku.jpg', 0)

if img is None: print ('Null Image') else:

cv.namedWindow('Trackbars')

cv.createTrackbar('kernel_W', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_W', 'Trackbars', 1)
cv.createTrackbar('kernel_H', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_H', 'Trackbars', 1)
cv.createTrackbar('bin_Th', 'Trackbars', 1, 255, nothing)
cv.setTrackbarPos('bin_Th', 'Trackbars', 1)

print (img.shape)
while True:

    kSize_w = cv.getTrackbarPos('kernel_W', 'Trackbars')
    kSize_h = cv.getTrackbarPos('kernel_H', 'Trackbars')
    bin_Th_val = cv.getTrackbarPos('bin_Th', 'Trackbars')

    _, mask = cv.threshold(img, bin_Th_val, 255, cv.THRESH_BINARY)

    kernel = np.ones((kSize_h,kSize_w), dtype = np.uint8)

    dilation= cv.dilate(mask, kernel, iterations = 3)

    cv.imshow('Initial Image', img)
    cv.imshow('Kernel', kernel)
    cv.imshow('mask', mask)
    cv.imshow('dilation', dilation)

    if cv.waitKey(2) == 27:
        break

np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?

code

import cv2 as cv import numpy as np

def nothing(x): pass

img = cv.imread('sudoku.jpg', 0)

if img is None: print ('Null Image') else:

cv.namedWindow('Trackbars')

cv.createTrackbar('kernel_W', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_W', 'Trackbars', 1)
cv.createTrackbar('kernel_H', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_H', 'Trackbars', 1)
cv.createTrackbar('bin_Th', 'Trackbars', 1, 255, nothing)
cv.setTrackbarPos('bin_Th', 'Trackbars', 1)

print (img.shape)
while True:

    kSize_w = cv.getTrackbarPos('kernel_W', 'Trackbars')
    kSize_h = cv.getTrackbarPos('kernel_H', 'Trackbars')
    bin_Th_val = cv.getTrackbarPos('bin_Th', 'Trackbars')

    _, mask = cv.threshold(img, bin_Th_val, 255, cv.THRESH_BINARY)

    kernel = np.ones((kSize_h,kSize_w), dtype = np.uint8)

    dilation= cv.dilate(mask, kernel, iterations = 3)

    cv.imshow('Initial Image', img)
    cv.imshow('Kernel', kernel)
    cv.imshow('mask', mask)
    cv.imshow('dilation', dilation)

    if cv.waitKey(2) == 27:
        break

np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?

code

import cv2 as cv import numpy as np

def nothing(x): pass

img = cv.imread('sudoku.jpg', 0)

if img is None: print ('Null Image') else:else: cv.namedWindow('Trackbars')

cv.namedWindow('Trackbars')

cv.createTrackbar('kernel_W', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_W', 'Trackbars', 1)
cv.createTrackbar('kernel_H', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_H', 'Trackbars', 1)
cv.createTrackbar('bin_Th', 'Trackbars', 1, 255, nothing)
cv.setTrackbarPos('bin_Th', 'Trackbars', 1)

print (img.shape)
while True:

    kSize_w = cv.getTrackbarPos('kernel_W', 'Trackbars')
    kSize_h = cv.getTrackbarPos('kernel_H', 'Trackbars')
    bin_Th_val = cv.getTrackbarPos('bin_Th', 'Trackbars')

    _, mask = cv.threshold(img, bin_Th_val, 255, cv.THRESH_BINARY)

    kernel = np.ones((kSize_h,kSize_w), dtype = np.uint8)

    dilation= cv.dilate(mask, kernel, iterations = 3)

    cv.imshow('Initial Image', img)
    cv.imshow('Kernel', kernel)
    cv.imshow('mask', mask)
    cv.imshow('dilation', dilation)

    if cv.waitKey(2) == 27:
        break

np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?


import cv2 as cv import numpy as np

def nothing(x): pass

img = cv.imread('sudoku.jpg', 0)

if img is None: print ('Null Image') else: cv.namedWindow('Trackbars')

cv.createTrackbar('kernel_W', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_W', 'Trackbars', 1)
cv.createTrackbar('kernel_H', 'Trackbars', 1, 100, nothing)
cv.setTrackbarPos('kernel_H', 'Trackbars', 1)
cv.createTrackbar('bin_Th', 'Trackbars', 1, 255, nothing)
cv.setTrackbarPos('bin_Th', 'Trackbars', 1)

print (img.shape)
while True:

    kSize_w = cv.getTrackbarPos('kernel_W', 'Trackbars')
    kSize_h = cv.getTrackbarPos('kernel_H', 'Trackbars')
    bin_Th_val = cv.getTrackbarPos('bin_Th', 'Trackbars')

    _, mask = cv.threshold(img, bin_Th_val, 255, cv.THRESH_BINARY)

    kernel = np.ones((kSize_h,kSize_w), dtype = np.uint8)

    dilation= cv.dilate(mask, kernel, iterations = 3)

    cv.imshow('Initial Image', img)
    cv.imshow('Kernel', kernel)
    cv.imshow('mask', mask)
    cv.imshow('dilation', dilation)

    if cv.waitKey(2) == 27:
        break

click to hide/show revision 9
None

updated 2020-10-01 06:27:35 -0600

berak gravatar image

np.ones() shape resize using cv.trackbar

I'm trying to create a variable sized kernel using np.ones method and trackbars in order to easily modify the size of the kernel. The problem seems to be that the width of the kernel does not decrease when the afferent parameter gets smaller. However this is not the case for the height of the kernel. The shape is correctly passed as a tuple of integers. Could anyone help me understand what's going on here?


import cv2 as cv
import numpy as np

np def nothing(x): pass

pass img = cv.imread('sudoku.jpg', 0)

0) if img is None: print ('Null Image') else: cv.namedWindow('Trackbars')

cv.namedWindow('Trackbars')

    cv.createTrackbar('kernel_W', 'Trackbars', 1, 100, nothing)
 cv.setTrackbarPos('kernel_W', 'Trackbars', 1)
 cv.createTrackbar('kernel_H', 'Trackbars', 1, 100, nothing)
 cv.setTrackbarPos('kernel_H', 'Trackbars', 1)
 cv.createTrackbar('bin_Th', 'Trackbars', 1, 255, nothing)
 cv.setTrackbarPos('bin_Th', 'Trackbars', 1)

 print (img.shape)
 while True:

     kSize_w = cv.getTrackbarPos('kernel_W', 'Trackbars')
     kSize_h = cv.getTrackbarPos('kernel_H', 'Trackbars')
     bin_Th_val = cv.getTrackbarPos('bin_Th', 'Trackbars')

     _, mask = cv.threshold(img, bin_Th_val, 255, cv.THRESH_BINARY)

     kernel = np.ones((kSize_h,kSize_w), dtype = np.uint8)

     dilation= cv.dilate(mask, kernel, iterations = 3)

     cv.imshow('Initial Image', img)
     cv.imshow('Kernel', kernel)
     cv.imshow('mask', mask)
     cv.imshow('dilation', dilation)

     if cv.waitKey(2) == 27:
         break