Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
coert committed Jun 8, 2024
1 parent 651f62d commit 21eba5f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module github.com/deosjr/elephanttalk

go 1.20
go 1.21

toolchain go1.22.2

require (
github.com/deosjr/whistle v0.0.0-20230606141022-90a4546b49c5
gocv.io/x/gocv v0.27.0
gocv.io/x/gocv v0.36.1-chessboard
)

require gonum.org/v1/gonum v0.15.0 // indirect

// replace gocv.io/x/gocv => ../../coert/gocv
replace gocv.io/x/gocv => ../gocv
6 changes: 3 additions & 3 deletions talk/calibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func calibration(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window
scChsBrd: scChsBrd,
}

if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle, scChsBrd straightChessboard) {
if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle) {
// find calibration pattern, draw around it
for k, v := range spatialPartition {
if !findCalibrationPattern(v) {
Expand Down Expand Up @@ -141,7 +141,7 @@ func calibration(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window
// ratio between webcam and beamer
displayRatio := 1.0

if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle, scChsBrd straightChessboard) {
if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle) {
gocv.Rectangle(&cimg, image.Rect(0, 0, beamerWidth, beamerHeight), color.RGBA{}, -1)
gocv.Line(&cimg, image.Pt(w-5+200, h), image.Pt(w+5+200, h), red, 2)
gocv.Line(&cimg, image.Pt(w+200., h-5), image.Pt(w+200, h+5), red, 2)
Expand Down Expand Up @@ -181,7 +181,7 @@ func calibration(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window
return calibrationResults{}
}

if err := frameloop(fi, func(actualImage image.Image, spatialPartition map[image.Rectangle][]circle, scChsBrd straightChessboard) {
if err := frameloop(fi, func(actualImage image.Image, spatialPartition map[image.Rectangle][]circle) {
gocv.Rectangle(&cimg, image.Rect(0, 0, beamerWidth, beamerHeight), color.RGBA{}, -1)

for k, v := range spatialPartition {
Expand Down
24 changes: 15 additions & 9 deletions talk/vision.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type frameInput struct {
scChsBrd straightChessboard
}

func frameloop(fi frameInput, f func(image.Image, map[image.Rectangle][]circle, straightChessboard), ref []color.RGBA, waitMillis int) error {
func frameloop(fi frameInput, f func(image.Image, map[image.Rectangle][]circle), ref []color.RGBA, waitMillis int) error {
for {
start := time.Now()
if ok := fi.webcam.Read(&fi.img); !ok {
Expand All @@ -61,16 +61,19 @@ func frameloop(fi frameInput, f func(image.Image, map[image.Rectangle][]circle,
if fi.img.Empty() {
continue
}

straightImage := beamerToChessboard(fi.img, fi.scChsBrd)

// since detect draws in img, we take a snapshot first
actualImage, _ := fi.img.ToImage()
actualImage, _ := straightImage.ToImage() //fi.img.ToImage()
spatialPartition := detect(fi.img, actualImage, ref)

f(actualImage, spatialPartition, fi.scChsBrd)
f(actualImage, spatialPartition)

fps := time.Second / time.Since(start)
gocv.PutText(&fi.img, fmt.Sprintf("FPS: %d", fps), image.Pt(0, 20), 0, .5, color.RGBA{}, 2)
gocv.PutText(&straightImage, fmt.Sprintf("FPS: %d", fps), image.Pt(0, 20), 0, .5, color.RGBA{}, 2)

fi.debugWindow.IMShow(fi.img)
fi.debugWindow.IMShow(straightImage)
fi.projection.IMShow(fi.cimg)
key := fi.debugWindow.WaitKey(waitMillis)
if key >= 0 {
Expand All @@ -85,6 +88,8 @@ func vision(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window, cRe
cimg := gocv.NewMatWithSize(beamerHeight, beamerWidth, gocv.MatTypeCV8UC3)
defer cimg.Close()

straightener := loadCalibration("calibration.json")

l := LoadRealTalk()
// translate to beamerspace
pixPerCM := cResults.pixelsPerCM
Expand All @@ -99,6 +104,7 @@ func vision(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window, cRe
projection: projection,
img: img,
cimg: cimg,
scChsBrd: straightener,
}

// ttl in frames; essentially buffering page location for flaky detection
Expand All @@ -109,7 +115,7 @@ func vision(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window, cRe

persistCorners := map[corner]persistPage{}

if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle, scChsBrd straightChessboard) {
if err := frameloop(fi, func(_ image.Image, spatialPartition map[image.Rectangle][]circle) {
clear(l)
datalogIDs := map[uint64]int{}

Expand Down Expand Up @@ -350,9 +356,9 @@ func vision(webcam *gocv.VideoCapture, debugwindow, projection *gocv.Window, cRe

// in lisp we store the points already translated to beamerspace instead of webcamspace
// NOTE: this means distances between papers in inches should use a conversion as well!
for i, pt := range pts {
pts[i] = translate(pt, cResults.displacement, cResults.displayRatio)
}
//for i, pt := range pts {
// pts[i] = translate(pt, cResults.displacement, cResults.displayRatio)
//}

dID := page2lisp(l, p, pts)
datalogIDs[p.id] = dID
Expand Down

0 comments on commit 21eba5f

Please sign in to comment.