Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are 2 steps. In cv.GaussianBlur, You can change odd number btween 15 to 21, but not even numbers to suit our needed. Step 1:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)
img = cv.bitwise_not(gray)
adp_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,15,-2)

horizontal_inv = cv.bitwise_not(adp_thresh.copy())
masked = cv.bitwise_and(img, img, mask=horizontal_inv)

inv_masked = cv.bitwise_not(masked)
cv.imshow('Masked', inv_masked)
cv.imwrite('masked.jpg', inv_masked)
cv.waitKey(0)
cv.destroyAllWindows()

Output: block

Step 2:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img=cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)

img = cv.bitwise_not(gray)
adapt_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 15, -2)
cv.imshow('adapt_thresh', adp_thresh)
#cv.imwrite('adapt_thresh.jpg', adp_thresh=)
cv.waitKey(0)
cv.destroyAllWindows()

Output: adapt_thresh.

There are 2 steps. In cv.GaussianBlur, You can change odd number btween 15 to 21, but not even numbers to suit our needed. Step 1:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)
img = cv.bitwise_not(gray)
adp_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,15,-2)

horizontal_inv = cv.bitwise_not(adp_thresh.copy())
masked = cv.bitwise_and(img, img, mask=horizontal_inv)

inv_masked = cv.bitwise_not(masked)
cv.imshow('Masked', inv_masked)
cv.imwrite('masked.jpg', inv_masked)
cv.waitKey(0)
cv.destroyAllWindows()

Output: block!block

Step 2:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img=cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)

img = cv.bitwise_not(gray)
adapt_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 15, -2)
cv.imshow('adapt_thresh', adp_thresh)
#cv.imwrite('adapt_thresh.jpg', adp_thresh=)
cv.waitKey(0)
cv.destroyAllWindows()

Output: adapt_thresh.!adapt_thresh.

There are 2 steps. In cv.GaussianBlur, You can change odd number btween 15 to 21, but not even numbers to suit our needed. Step 1:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)
img = cv.bitwise_not(gray)
adp_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,15,-2)

horizontal_inv = cv.bitwise_not(adp_thresh.copy())
masked = cv.bitwise_and(img, img, mask=horizontal_inv)

inv_masked = cv.bitwise_not(masked)
cv.imshow('Masked', inv_masked)
cv.imwrite('masked.jpg', inv_masked)
cv.waitKey(0)
cv.destroyAllWindows()

Output: !blockOutput: block.jpg

Step 2:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img=cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)

img = cv.bitwise_not(gray)
adapt_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 15, -2)
cv.imshow('adapt_thresh', adp_thresh)
#cv.imwrite('adapt_thresh.jpg', adp_thresh=)
cv.waitKey(0)
cv.destroyAllWindows()

Output: !adapt_thresh.Output:

Adapt_thresh