Last answered:

30 Nov 2023

Posted on:

27 Nov 2023

0

Incomplete image is displayed

After executing the code, the image displayed is incomplete, meaning all coins do not appear in the window even after maximizing. Attached is the screenshot of the image


 

5 answers ( 0 marked as helpful)
Instructor
Posted on:

27 Nov 2023

0

Hey Dhaivat,


Thanks for reaching out.


Could you please copy-paste the code you are running? Are you using PyCharm?


Kind regards,

365 Hristina

Posted on:

27 Nov 2023

0

Hello Hristina,

I am using VS Code. Below is the code:

import numpy as np
import cv2
img = cv2.imread('capstone_coins.png',cv2.IMREAD_GRAYSCALE)
org_img = cv2.imread('capstone_coins.png',1)
img = cv2.GaussianBlur(img,(5,5),0)
cv2.imshow('Detected Coins',org_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Instructor
Posted on:

27 Nov 2023

0

Hey again Dhaivat,


Unfortunately, I'm not certain why this issue occurs. Please, experiment with the following:

- try to increase your display resolution

- alternatively, modify your code by adding the following line of code before executing imshow:

cv2.resize

- or maybe add the following, again before executing imshow:

cv2.WINDOW_NORMAL

Let me know if any of the following solved the problem.

Kind regards,

365 Hristina

Posted on:

27 Nov 2023

0

Sorry, but none of them works. Stuck!!

Posted on:

30 Nov 2023

0

Hello Hristina,

Just wanted to let you know that I resolved the issue as follows:

I had to truncate the image using any image-editing tool (cropping, basically). This changed the image size and the entire image could be displayed. So, I had to fiddle a bit with the argument values in cv2.HoughCircles function (with param1, param2, minDistance, etc). It detected all the circles finally. It also detected an additional circle, which I could remove by adjusting the GaussianBlur kernel size to (7,7).  The only aspects which I made different from Giles's solution are as below (rest of the code is the same):

img = cv2.GaussianBlur(img,(7,7),0)

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,150,param1=33,param2=31,minRadius=40,maxRadius=130)


So, basically, this looks like a trial-and-error solution and there is no one way in which a program working on 1 computer would definitely work on another computer. In such a scenario, would it not be an issue if we make a program for a customer and then it doesn't work on their computer? So, though I have been able to resolve my issue by trying out certain values, I am really concerned about the query and how can we resolve this. Can you please elaborate?

Submit an answer