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

Chapter_1\bayes.py #1

Open
Royml opened this issue Jan 2, 2021 · 10 comments
Open

Chapter_1\bayes.py #1

Royml opened this issue Jan 2, 2021 · 10 comments

Comments

@Royml
Copy link

Royml commented Jan 2, 2021

Chapter_1\bayes.py", line 234, in main
cv.circle(app.img, (sailor_x, sailor_y), 3, (255, 0, 0), -1)
TypeError: only integer scalar arrays can be converted to a scalar index

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 2, 2021

Hi Royml, I'm unable to reproduce the error on Windows or macOS. Try turning the sailor coordinates into a tuple: cv.circle(app.img, ((sailor_x, sailor_y)), 3, (255, 0, 0), -1). If this doesn't help, try running the bayes.py code downloaded from github. This ran okay for me. Let me know how it goes.

@Royml
Copy link
Author

Royml commented Jan 3, 2021

Hi, the tupl(ing) didn't fix it, but I did manage to resolve with int() on the sailor_x and sailor_y.

It could be a python version issue, mine is 3.8.5

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 3, 2021

Okay. I'm in the process of transferring to a new computer and installing Anaconda with the latest version of Python. I'll revisit this when I have everything up and running in the next week or so. Thanks.

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 3, 2021

Could you also let me know which version of OpenCV you are using? Thanks.

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 3, 2021

cv.circle(app.img, (sailor_x.item(0), sailor_y.item(0)), 3, (255, 0, 0), -1) # Returns a standard Python scalar and should fix the problem. Alternatively, using sailor_x[0] and sailor_y[0] should also work.

A better solution would be changing lines 90 & 91 to the following:
self.sailor_actual[0] = np.random.choice(self.sa1.shape[1])
self.sailor_actual[1] = np.random.choice(self.sa1.shape[0])

This returns an integer directly so no need to jump through hoops. Thanks to Alexander Valarus for pointing this out.

@dougler
Copy link

dougler commented Jan 16, 2021

getting the sailor position to show
I could not get the last "else" line cv.circle...to work
I had to modify the draw _map method with an extra parameter 'actual_position' which is set to(0,00 when the not wanted and to the position when wanted
the draw_map method then includes the "cv. circle.." which is activated when actual_position !=(0,0)

I also had to destroyAlllWindows after the imshow to get the draw_map to work twice

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 16, 2021

Hmmm. A few questions:
-What OS are you using?
-Are you launching the program from a terminal/powershell or from your IDE?
-Are you running the bayes.py I supplied on github? This has been tested on multiple systems.

@dougler
Copy link

dougler commented Jan 16, 2021 via email

@rlvaugh
Copy link
Owner

rlvaugh commented Jan 17, 2021

That's good news! It's easy to mistype something going from the book to the keyboard. If you run the supplied code and it works differently, you can compare your code to mine using online comparison tools or by pasting the code into two different Microsoft Word docs and then using the compare feature under the Review tab. This will highlight any changes, making them easy to find.

@dougler
Copy link

dougler commented Jan 17, 2021 via email

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

3 participants