img=r"C:\5_cube.tif"
img = cv2.imread(img, cv2.IMREAD_COLOR)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#Code to Find edges of Square using Canny edge detection method and finding contours and drawing in Back Line
edges = cv2.Canny(img_gray, 0, 100)
im2, contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 0, 0), 5)
#Save contours
cv2.imwrite(r"C:\Users\burli\Desktop\1.tif",img)
Now we will read Resized image, Resize the contours and apply the contours on the Resized Image
image_resize=r"C:\ImageResize.tif"
image_resize = cv2.imread(image_resize, cv2.IMREAD_COLOR)
height = np.size(image_resize, 0)
width = np.size(image_resize, 1)
ratio = width/height
CounterNewValue = np.multiply(ratio, contours)
NewconterList = []
for i in CounterNewValue:
for j in range(len(i)):
CounterNewValue[j] = CounterNewValue[j].astype(int)
cv2.drawContours(image_resize, CounterNewValue, -1, (0, 0, 0), 5)
cv2.imwrite(r"C:\3.tif",image_resize)
Is there Some thing i am doing wrong ? Error Message
Traceback (most recent call last):
File "C:/EffectMainFunction.py", line 17, in <module>
ObjConturesCreation.ExtractColorFromImage()
File "C:\conturesCreation.py", line 34, in ExtractColorFromImage
cv2.drawContours(image_resize, CounterNewValue, -1, (0, 0, 0), 5)
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2511: error: (-215:Assertion failed) npoints > 0 in function 'cv::drawContours'