-
Notifications
You must be signed in to change notification settings - Fork 111
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
[DATA-535] Create an orbslam integration test that runs mono YCbCr im… #1502
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
package builtin_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"image" | ||
|
@@ -41,16 +42,27 @@ import ( | |
) | ||
|
||
const ( | ||
validDataRateMS = 200 | ||
numOrbslamImages = 29 | ||
validDataRateMS = 200 | ||
) | ||
|
||
var ( | ||
orbslamIntCameraMutex sync.Mutex | ||
orbslamIntCameraReleaseImagesChan chan int = make(chan int, 2) | ||
orbslamIntWebcamReleaseImageChan chan int = make(chan int, 1) | ||
orbslamIntSynchronizeCamerasChan chan int = make(chan int) | ||
) | ||
|
||
func getNumOrbslamImages(mode slam.Mode) int { | ||
switch mode { | ||
case slam.Mono: | ||
return 15 | ||
case slam.Rgbd: | ||
return 29 | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
func createFakeSLAMLibraries() { | ||
for _, s := range slam.SLAMLibraries { | ||
slam.SLAMLibraries["fake_"+s.AlgoName] = slam.LibraryMetadata{ | ||
|
@@ -103,22 +115,39 @@ func setupInjectRobot() *inject.Robot { | |
distortionsA := &transform.BrownConrady{RadialK1: 0.001, RadialK2: 0.00004} | ||
projA = intrinsicsA | ||
|
||
var projReal transform.Projector | ||
intrinsicsReal := &transform.PinholeCameraIntrinsics{ | ||
var projRealSense transform.Projector | ||
intrinsicsRealSense := &transform.PinholeCameraIntrinsics{ | ||
Width: 1280, | ||
Height: 720, | ||
Fx: 900.538, | ||
Fy: 900.818, | ||
Ppx: 648.934, | ||
Ppy: 367.736, | ||
} | ||
distortionsReal := &transform.BrownConrady{ | ||
distortionsRealSense := &transform.BrownConrady{ | ||
RadialK1: 0.158701, | ||
RadialK2: -0.485405, | ||
RadialK3: 0.435342, | ||
TangentialP1: -0.00143327, | ||
TangentialP2: -0.000705919} | ||
projReal = intrinsicsReal | ||
projRealSense = intrinsicsRealSense | ||
|
||
var projWebcam transform.Projector | ||
intrinsicsWebcam := &transform.PinholeCameraIntrinsics{ | ||
Width: 640, | ||
Height: 480, | ||
Fx: 939.2693584627577, | ||
Fy: 940.2928257873841, | ||
Ppx: 320.6075282958033, | ||
Ppy: 239.14408757087756, | ||
} | ||
distortionsWebcam := &transform.BrownConrady{ | ||
RadialK1: 0.046535971648456166, | ||
RadialK2: 0.8002516496932317, | ||
RadialK3: -5.408034254951954, | ||
TangentialP1: -8.996658362365533e-06, | ||
TangentialP2: -0.002828504714921335} | ||
projWebcam = intrinsicsWebcam | ||
|
||
r.ResourceByNameFunc = func(name resource.Name) (interface{}, error) { | ||
cam := &inject.Camera{} | ||
|
@@ -249,10 +278,10 @@ func setupInjectRobot() *inject.Robot { | |
return nil, errors.New("camera not lidar") | ||
} | ||
cam.ProjectorFunc = func(ctx context.Context) (transform.Projector, error) { | ||
return projReal, nil | ||
return projRealSense, nil | ||
} | ||
cam.PropertiesFunc = func(ctx context.Context) (camera.Properties, error) { | ||
return camera.Properties{IntrinsicParams: intrinsicsReal, DistortionParams: distortionsReal}, nil | ||
return camera.Properties{IntrinsicParams: intrinsicsRealSense, DistortionParams: distortionsRealSense}, nil | ||
} | ||
var index uint64 | ||
cam.StreamFunc = func(ctx context.Context, errHandlers ...gostream.ErrorHandler) (gostream.VideoStream, error) { | ||
|
@@ -265,7 +294,7 @@ func setupInjectRobot() *inject.Robot { | |
select { | ||
case <-orbslamIntCameraReleaseImagesChan: | ||
i := atomic.AddUint64(&index, 1) - 1 | ||
if i >= numOrbslamImages { | ||
if i >= uint64(getNumOrbslamImages(slam.Rgbd)) { | ||
return nil, errors.New("No more orbslam color images") | ||
} | ||
imgBytes, err := os.ReadFile(artifact.MustPath("slam/mock_camera_short/rgb/" + strconv.FormatUint(i, 10) + ".png")) | ||
|
@@ -304,7 +333,7 @@ func setupInjectRobot() *inject.Robot { | |
select { | ||
case <-orbslamIntCameraReleaseImagesChan: | ||
i := atomic.AddUint64(&index, 1) - 1 | ||
if i >= numOrbslamImages { | ||
if i >= uint64(getNumOrbslamImages(slam.Rgbd)) { | ||
return nil, errors.New("No more orbslam depth images") | ||
} | ||
imgBytes, err := os.ReadFile(artifact.MustPath("slam/mock_camera_short/depth/" + strconv.FormatUint(i, 10) + ".png")) | ||
|
@@ -322,6 +351,44 @@ func setupInjectRobot() *inject.Robot { | |
} | ||
} | ||
return cam, nil | ||
case camera.Named("orbslam_int_webcam"): | ||
cam.NextPointCloudFunc = func(ctx context.Context) (pointcloud.PointCloud, error) { | ||
return nil, errors.New("camera not lidar") | ||
} | ||
cam.ProjectorFunc = func(ctx context.Context) (transform.Projector, error) { | ||
return projWebcam, nil | ||
} | ||
cam.PropertiesFunc = func(ctx context.Context) (camera.Properties, error) { | ||
return camera.Properties{IntrinsicParams: intrinsicsWebcam, DistortionParams: distortionsWebcam}, nil | ||
} | ||
var index uint64 | ||
cam.StreamFunc = func(ctx context.Context, errHandlers ...gostream.ErrorHandler) (gostream.VideoStream, error) { | ||
select { | ||
case <-orbslamIntWebcamReleaseImageChan: | ||
i := atomic.AddUint64(&index, 1) - 1 | ||
if i >= uint64(getNumOrbslamImages(slam.Mono)) { | ||
return nil, errors.New("No more orbslam webcam images") | ||
} | ||
imgBytes, err := os.ReadFile(artifact.MustPath("slam/mock_mono_camera/rgb/" + strconv.FormatUint(i, 10) + ".png")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
img, _, err := image.Decode(bytes.NewReader(imgBytes)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var ycbcrImg image.YCbCr | ||
rimage.ImageToYCbCrForTesting(&ycbcrImg, img) | ||
return gostream.NewEmbeddedVideoStreamFromReader( | ||
gostream.VideoReaderFunc(func(ctx context.Context) (image.Image, func(), error) { | ||
return &ycbcrImg, func() {}, nil | ||
}), | ||
), nil | ||
Comment on lines
+372
to
+386
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had JPEG images, you could use the github.com/pixiv/go-libjpeg package and use its Decode function, which outputs YCbCr images directly: github.com/pixiv/go-libjpeg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you need the libjpeg library to use that package - which may not be present on our CI/canon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the idea! I think I'll leave as is. |
||
default: | ||
return nil, errors.Errorf("Webcam not ready to return image %v", index) | ||
} | ||
} | ||
return cam, nil | ||
default: | ||
return nil, rdkutils.NewResourceNotFoundError(name) | ||
} | ||
|
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.
I couldn't find another was to convert to YCbCr, so I exported this function. Let me know if you have another idea!
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.
you can probably use the draw.Draw function to do this
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.
It doesn't look like I can do this, since image.YCbCr doesn't implement draw.Image (missing method Set).
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.
oh wow, yea it looks like YCbCr isn't pixel addressable! So, yea, this function seems like the best bet for now
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.
Just found an alternative - but if you would like to stick to using one set of images (the png sources) then what you have now seems like the way to go