while using cv2.drawContours to display the counters, the contours are not displayed. While using cv.2 drawContours, I am getting no errors. As I am new to python, I am not able to figure out what the code is lacking. Thanks in advance for help.
My code is as follow:
while I am trying to upload the image, the URL link is coming but the image is on my laptop. I have written the URL for image from my laptop. But the image is not getting flashed along with question?
Please guide me to upload the image. Sorry for the request.
My code is as follow:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import skimage
from skimage import io
from skimage import filters
from skimage.color import rgb2gray
import cv2
from skimage import morphology
from skimage.morphology import disk
from scipy import ndimage
testimage = io.imread('testimage.jpg');
grayscale = rgb2gray(testimage)
threshold_value = filters.threshold_otsu(grayscale)
threshold_value
nrows, ncols = grayscale.shape
dim = (nrows, ncols)
img_bin = np.zeros(dim)
for i in range(0,nrows,1):
for j in range(0,ncols,1):
if (grayscale[i][j] > threshold_value):
img_bin[i][j] = 255;
img_bin = img_bin.astype('uint8')
img_bin3 = morphology.remove_small_objects(img_bin, min_size=35, connectivity=4)
radius = 2
selem = disk(radius)
img3 = cv2.dilate(img_bin, selem, iterations= 1)
img4 = cv2.erode(img3, selem, iterations= 1)
fill_particles = ndimage.binary_fill_holes(img4)
img5 = ndimage.median_filter(fill_particles, [1,1])
plt.imshow(fill_particles, cmap = 'gray')
img5 = img5.astype('uint8')
_,contours, hierarchy = cv2.findContours(img5, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
print("Number of Contours found = " + str(len(contours)))
cv2.drawContours(img5, contours, -1, (0, 255, 0), 20)
plt.imshow(img5, 'gray')while I am trying to upload the image, the URL link is coming but the image is on my laptop. I have written the URL for image from my laptop. But the image is not getting flashed along with question?
Please guide me to upload the image. Sorry for the request.
