Skip to content

Commit 4f2b707

Browse files
authored
DOCS-3196: Update vision docs for camera interface update (viamrobotics#4717)
1 parent 8222d44 commit 4f2b707

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

services/vision/vision.go

+42-48
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,29 @@ func init() {
6161
//
6262
// Detections example:
6363
//
64-
// myCam, err := camera.FromRobot(machine, "my_camera")
65-
// if err != nil {
66-
// logger.Error(err)
67-
// return
68-
// }
69-
// // Get the stream from a camera
70-
// camStream, err := myCam.Stream(context.Background())
71-
// // Get an image from the camera stream
72-
// img, release, err := camStream.Next(context.Background())
73-
// defer release()
64+
// // add "go.viam.com/rdk/utils" to imports to use this code snippet
7465
//
75-
// myDetectorService, err := vision.FromRobot(machine, "my_detector")
76-
// if err != nil {
77-
// logger.Error(err)
78-
// return
79-
// }
80-
// // Get the detections from the image
81-
// detections, err := myDetectorService.Detections(context.Background(), img, nil)
82-
// if err != nil {
83-
// logger.Fatalf("Could not get detections: %v", err)
84-
// }
85-
// if len(detections) > 0 {
86-
// logger.Info(detections[0])
87-
// }
66+
// myCam, err := camera.FromRobot(machine, "my_camera")
67+
// if err != nil {
68+
// logger.Error(err)
69+
// return
70+
// }
71+
// // Get an image from the camera decoded as an image.Image
72+
// img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
73+
//
74+
// myDetectorService, err := vision.FromRobot(machine, "my_detector")
75+
// if err != nil {
76+
// logger.Error(err)
77+
// return
78+
// }
79+
// // Get the detections from the image
80+
// detections, err := myDetectorService.Detections(context.Background(), img, nil)
81+
// if err != nil {
82+
// logger.Fatalf("Could not get detections: %v", err)
83+
// }
84+
// if len(detections) > 0 {
85+
// logger.Info(detections[0])
86+
// }
8887
//
8988
// For more information, see the [Detections method docs].
9089
//
@@ -108,34 +107,29 @@ func init() {
108107
//
109108
// Classifications example:
110109
//
111-
// myCam, err := camera.FromRobot(machine, "my_camera")
112-
// if err != nil {
113-
// logger.Error(err)
114-
// return
115-
// }
116-
// // Get the stream from a camera
117-
// camStream, err := myCam.Stream(context.Background())
118-
// if err!=nil {
110+
// // add "go.viam.com/rdk/utils" to imports to use this code snippet
111+
//
112+
// myCam, err := camera.FromRobot(machine, "my_camera")
113+
// if err != nil {
119114
// logger.Error(err)
120115
// return
121-
// }
122-
// // Get an image from the camera stream
123-
// img, release, err := camStream.Next(context.Background())
124-
// defer release()
116+
// }
117+
// // Get an image from the camera decoded as an image.Image
118+
// img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
125119
//
126-
// myClassifierService, err := vision.FromRobot(machine, "my_classifier")
127-
// if err != nil {
128-
// logger.Error(err)
129-
// return
130-
// }
131-
// // Get the 2 classifications with the highest confidence scores from the image
132-
// classifications, err := myClassifierService.Classifications(context.Background(), img, 2, nil)
133-
// if err != nil {
134-
// logger.Fatalf("Could not get classifications: %v", err)
135-
// }
136-
// if len(classifications) > 0 {
137-
// logger.Info(classifications[0])
138-
// }
120+
// myClassifierService, err := vision.FromRobot(machine, "my_classifier")
121+
// if err != nil {
122+
// logger.Error(err)
123+
// return
124+
// }
125+
// // Get the 2 classifications with the highest confidence scores from the image
126+
// classifications, err := myClassifierService.Classifications(context.Background(), img, 2, nil)
127+
// if err != nil {
128+
// logger.Fatalf("Could not get classifications: %v", err)
129+
// }
130+
// if len(classifications) > 0 {
131+
// logger.Info(classifications[0])
132+
// }
139133
//
140134
// For more information, see the [Classifications method docs].
141135
//

0 commit comments

Comments
 (0)