Skip to content

Code not working at page 145 #1

Open
@arafat877

Description

@arafat877

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions