-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add AxisCamera sample #103
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) FIRST and other WPILib contributors. | ||
# Open Source Software; you can modify and/or share it under the terms of | ||
# the WPILib BSD license file in the root directory of this project. | ||
# | ||
|
||
|
||
import wpilib | ||
import wpilib.cameraserver | ||
|
||
|
||
""" | ||
* This is a demo program showing the use of OpenCV to do vision processing. The image is acquired | ||
* from the Axis camera, then a rectangle is put on the image and sent to the dashboard. OpenCV has | ||
* many methods for different types of processing. | ||
""" | ||
|
||
|
||
class MyRobot(wpilib.TimedRobot): | ||
def robotInit(self): | ||
# Your image processing code will be launched via a stub that will set up logging and initialize NetworkTables | ||
# to talk to your robot code. | ||
# https://robotpy.readthedocs.io/en/stable/vision/roborio.html#important-notes | ||
|
||
wpilib.CameraServer.launch("vision.py:main") | ||
|
||
|
||
if __name__ == "__main__": | ||
wpilib.run(MyRobot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# Copyright (c) FIRST and other WPILib contributors. | ||
# Open Source Software; you can modify and/or share it under the terms of | ||
# the WPILib BSD license file in the root directory of this project. | ||
# | ||
|
||
|
||
import ntcore | ||
import numpy | ||
from cscore import CameraServer | ||
import cv2 | ||
|
||
|
||
# | ||
# This code will work both on a RoboRIO and on other platforms. The exact mechanism | ||
# to run it differs depending on whether you’re on a RoboRIO or a coprocessor | ||
# | ||
# https://robotpy.readthedocs.io/en/stable/vision/code.html | ||
|
||
|
||
def main(): | ||
# Get the Axis camera from CameraServer | ||
|
||
camera = CameraServer.addAxisCamera("axis-camera.local") | ||
# Set the resolution | ||
|
||
camera.setResolution(640, 480) | ||
|
||
# Get a CvSink. This will capture Mats from the camera | ||
|
||
cvSink = CameraServer.getVideo() | ||
# Setup a CvSource. This will send images back to the Dashboard | ||
|
||
outputStream = CameraServer.putVideo("Rectangle", 640, 480) | ||
|
||
# Mats are very memory expensive. Lets reuse this Mat. | ||
|
||
mat = numpy.zeros((480, 640, 3), dtype="uint8") | ||
|
||
# Declare the color of the rectangle | ||
|
||
rectColor = (255, 255, 255) | ||
|
||
# The camera code will be killed when the robot.py program exits. If you wish to perform cleanup, | ||
# you should register an atexit handler. The child process will NOT be launched when running the robot code in | ||
# simulation or unit testing mode | ||
|
||
while True: | ||
# Tell the CvSink to grab a frame from the camera and put it in the source mat. If there is an error notify the | ||
# output. | ||
|
||
if cvSink.grabFrame(mat) == 0: | ||
# Send the output the error. | ||
|
||
outputStream.notifyError(cvSink.getError()) | ||
# skip the rest of the current iteration | ||
|
||
continue | ||
# Put a rectangle on the image | ||
|
||
mat = cv2.rectangle( | ||
img=mat, | ||
pt1=(100, 100), | ||
pt2=(400, 400), | ||
color=rectColor, | ||
lineType=5, | ||
) | ||
# Give the output stream a new image to display | ||
|
||
outputStream.putFrame(mat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good, but can you associate the comments with the lines that they're with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with c62dc87