Sfoglia il codice sorgente

Attempting to group like points together

If we can start grouping points together, we can then track a "cloud", from there we can determine between frames it's direction, and attempt to determine if it will "hit" NPR... if so we can mark that (in the finished product I'd want red outlines around clouds that appear to be on intercept with NPR).

> In the __future__ I'll want to make it so this will run on a set of gifs from the live source, this would actually be avalible on my site (if I can just figure out how to make this happen).
Steve Thielemann 1 anno fa
parent
commit
e79ee82a72
2 ha cambiato i file con 68 aggiunte e 38 eliminazioni
  1. 1 0
      .gitignore
  2. 67 38
      main.go

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 *.gif
 *.gif
 *.png
 *.png
 *.json
 *.json
+*.txt
 *.log
 *.log
 
 

+ 67 - 38
main.go

@@ -6,40 +6,42 @@ import (
 	"image/color"
 	"image/color"
 	"image/gif"
 	"image/gif"
 	"log"
 	"log"
+	"sort"
+
+	"git.red-green.com/david/point2d"
 )
 )
 
 
-func main() {
+type HitList []point2d.Point
+
+func (h HitList) Len() int {
+	return len(h)
+}
+
+func (h HitList) Swap(i, j int) {
+	h[i], h[j] = h[j], h[i]
+}
+
+func (h HitList) Less(i, j int) bool {
+	return h[i].LessThan(&h[j])
+}
+
+func Scan(filename string) (hits []HitList, err error) {
 	var (
 	var (
-		err        error
-		gif        *gif.GIF
-		size       image.Point
-		pix        color.Color
-		r          uint32
-		g          uint32
-		b          uint32
-		hits       uint32
-		total_hits uint64
+		gif      *gif.GIF
+		size     image.Point
+		pix      color.Color
+		r        uint32
+		g        uint32
+		b        uint32
+		hitframe HitList
 	)
 	)
-	/*
-		err = GrabPascoGif()
-		if err != nil {
-			log.Panic("GrabPascoGif() >", err)
-		}
-		err = GrabCentralFloridaGif()
-		if err != nil {
-			log.Panic("GrabCentralFloridaGif() >", err)
-		}
-	*/
-
-	gif, err = DecodeGif("pasco.gif")
+	gif, err = DecodeGif(filename)
 	if err != nil {
 	if err != nil {
-		log.Panic("DecodeGif(\"pasco.gif\") >", err)
+		return nil, fmt.Errorf("DecodeGif(\"%s\") > %v", filename, err)
 	}
 	}
-
-	total_hits = 0
-	for frame_num, frame := range gif.Image {
+	for _, frame := range gif.Image {
 		size = frame.Bounds().Size()
 		size = frame.Bounds().Size()
-		hits = 0
+		hitframe = HitList{}
 		for y := range make([]byte, size.Y) {
 		for y := range make([]byte, size.Y) {
 			for x := range make([]byte, size.X) {
 			for x := range make([]byte, size.X) {
 				pix = frame.At(x, y)
 				pix = frame.At(x, y)
@@ -48,26 +50,53 @@ func main() {
 				g /= 255
 				g /= 255
 				b /= 255
 				b /= 255
 				// Now to determine if this pixel is considerable as rain
 				// Now to determine if this pixel is considerable as rain
-				if r <= 140 && g >= 120 && b <= 140 {
-					//fmt.Printf("{(%d, %d) [%d, %d, %d]} ", x, y, r, g, b)
+				if (r <= 47 && g >= 90 && b <= 51) || (r >= 240 && g >= 240 && b <= 10) || (r >= 240 && g <= 10 && b <= 10) {
+					//fmt.Printf("{(%d, %d) [%d, %d, %d, %s]}\r\n", x, y, r, g, b, rgbToHex(r, g, b))
 					frame.Set(x, y, color.RGBA{R: 255, G: 0, B: 0, A: 255})
 					frame.Set(x, y, color.RGBA{R: 255, G: 0, B: 0, A: 255})
-					hits += 1
+					hitframe = append(hitframe, *point2d.AsPoint(x, y))
 				}
 				}
 			}
 			}
 		}
 		}
-		fmt.Printf("%s-%d: %d hits\r\n", "pasco.gif", frame_num, hits)
-		total_hits += uint64(hits)
+		hits = append(hits, hitframe)
 	}
 	}
-	fmt.Printf("%s: %d total hits\r\n", "pasco.gif", total_hits)
-
-	err = EncodeGif("out", gif)
+	err = EncodeGif(filename+".out", gif)
 	if err != nil {
 	if err != nil {
-		log.Panic("EncodeGif(\"out\", gif) >", err)
+		return nil, fmt.Errorf("EncodeGif(\"%s.out\", gif) > %v", filename, err)
 	}
 	}
+	return hits, nil
+}
+
+func main() {
+	var (
+		err  error
+		hits []HitList
+		diff point2d.Point
+	)
 	/*
 	/*
-		err = EncodeGif("out", gif, true)
+		err = GrabPascoGif()
 		if err != nil {
 		if err != nil {
-			log.Panic("EncodeGif(\"out\", gif, true) >", err)
+			log.Panic("GrabPascoGif() >", err)
 		}
 		}
 	*/
 	*/
+
+	hits, err = Scan("pasco.gif")
+	if err != nil {
+		log.Panic(err)
+	}
+	for _, frame := range hits {
+		sort.Sort(&frame)
+	}
+	for _, pos := range hits[0] {
+		if diff.IsZero() {
+			diff = pos
+		} else {
+			dist := diff.DistanceTo(&pos)
+			if dist > 1 {
+				fmt.Printf("0] (%s) diff=(%s) dist=%d\r\n", pos.String(), diff.String(), dist)
+			}
+			if dist > 1 {
+				diff = pos
+			}
+		}
+	}
 }
 }