Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code not working at page 145 #1

Open
arafat877 opened this issue Dec 21, 2021 · 1 comment
Open

Code not working at page 145 #1

arafat877 opened this issue Dec 21, 2021 · 1 comment
Assignees

Comments

@arafat877
Copy link

arafat877 commented Dec 21, 2021

Please use this template while reporting bugs inside PPaO. Issues related to personal project questions or code that we haven't authored will automatically be closed.

Are you using one of our development environments?

We provide a preconfigured AWS AMI and a VM to help our customers skip the environment setup part and jump straight to development. We highly suggest using one of our development environments to run our code.

If the issue is not related to code, then you can simply skip this question.

If you are using your own development environment then please provide the following details.

  • GPU model and CUDA version: (skip if not application)
  • OS Platform: Windows 10
  • Python version: 3.8.2
  • OpenCV version: 4.5.3.58

Code not working at page 145

18 (_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)

the above code should be fixed, because according to the Python doc, the code should be written as 👍

18 cnts, _ = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)

En plus if I use the following image(https://media.istockphoto.com/photos/coins-picture-id92890281), the above code didn't work correctly, it shows a lot of black circles upon the coins .

the solution is that we should calculate the threshold1 and threshold2, and the code should look as the following :

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (7, 7), 0)
median = np.median(image)
lower = int(max(0, 0.67 * median))
upper = int(min(255, (1.33) * median))

canny = cv2.Canny(blurred, lower, upper)
contours, hierachy = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
coins = cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
cv2.imshow("Coins", coins)
cv2.waitKey(0)
@arafat877
Copy link
Author

This is the solution that I have found for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants