GithubHelp home page GithubHelp logo

Team 5414 Code Review about frc-2020 HOT 5 CLOSED

chopshop-166 avatar chopshop-166 commented on September 25, 2024
Team 5414 Code Review

from frc-2020.

Comments (5)

msoucy avatar msoucy commented on September 25, 2024

Thank you for your feedback!

  • Would you happen to have more information on preallocating with Python? I found a reference but it appears to not have a good answer. It's definitely something that would be nice to do.
  • We chose inline methods because we want the external interface for all subsystems, to be the command interface. While this does cause the subsystem to be longer, it also reduces the odds of the subsystem's rules being violated (things happening without being commanded). It's a discussion that we may reopen for more complex commands.
  • We found the RobotContainer to not serve sufficient purpose for our needs at this time, given our use of maps as classes. After reconsidering based on your prompting, we have determined that the container setup may be useful for the map setup after all. It's something we're going to investigate, thank you.

from frc-2020.

bryanyli avatar bryanyli commented on September 25, 2024

Preallocating is just creating variables outside of the main loop. Basically, what you'd need to do is something like this:

img = np.zeros((height, width, 3), dtype = np.uint8)
hsv_img = np.zeros((height, width, 3), dtype = np.uint8)
binary_img =  np.zeros((height, width, 3), dtype = np.uint8)
output_img =  np.zeros((height, width, 3), dtype = np.uint8)

while True:
  img = frame.get_data()
  hsv_img = cv2.cvtColor(...)
  etc.

However, for your imgfilter function, you have to add args for the preallocated matrices so that you can modify them within the function.

from frc-2020.

msoucy avatar msoucy commented on September 25, 2024

In the example you give, you allocate memory - and then remove the reference to them when you assign a new value using =. I'd just like to make sure that that's clear. Using OpenCV currently, there doesn't appear to be a way to pass in a buffer to write into.

from frc-2020.

bryanyli avatar bryanyli commented on September 25, 2024

Having ran some benchmarks, it does seem like what you say is true. I've also tried with np.copyto() and arr[:] = ..., and all 4 methods time pretty similarly. Sorry for the misunderstanding, I assumed that the image would be read into the preallocated array rather than assigning a new array.

from frc-2020.

msoucy avatar msoucy commented on September 25, 2024

No worries! In many situations it would definitely be good advice. The only reasons it isn't in this case, is that opencv doesn't provide a way to pass in a buffer for the output, and that Python uses reference variables.

For future readers:

What this means is that when you use x = y, you make x and y refer to the exact same object, not two identical objects. For things like integers, or things that can't be modified in place, that's fine. But if you do it in a list, it can have surprising behavior. x = []; y = x; y.append(5); assert len(x) == 1 is correct, since x and y refer to the same list.

So in the example you gave above, opencv would construct a new buffer object, and then change hsv_img to reference that buffer object, instead of filling the existing buffer. The other methods you showed (arr[:] and np.copyto) should actually be slightly slower, since they still construct/allocate the new buffer, and then spend extra time copying the values into the existing buffer.

from frc-2020.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.