From a7dad2b8c19542db91664592be4c10be3be99777 Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Sat, 16 Nov 2019 13:25:37 -0500
Subject: [PATCH] swap

---
 hunks/adhoc/correlate.js                | 80 ++++++++++++++++++++
 hunks/adhoc/fftest.js                   | 18 -----
 hunks/adhoc/webcam.js                   |  1 -
 save/contexts/cuttlefish/correlate.json | 82 +++++++++++++++++++++
 save/systems/fft.json                   | 98 +++++++++++++++++++++++++
 5 files changed, 260 insertions(+), 19 deletions(-)
 create mode 100644 hunks/adhoc/correlate.js
 delete mode 100644 hunks/adhoc/fftest.js
 create mode 100644 save/contexts/cuttlefish/correlate.json
 create mode 100644 save/systems/fft.json

diff --git a/hunks/adhoc/correlate.js b/hunks/adhoc/correlate.js
new file mode 100644
index 0000000..957cd95
--- /dev/null
+++ b/hunks/adhoc/correlate.js
@@ -0,0 +1,80 @@
+/*
+
+attempt of fft cross correlation for fast tracking / subpixel measurements
+
+*/
+
+import {
+  Hunkify,
+  Input,
+  Output,
+  State
+} from '../hunks.js'
+
+let correlate = (A, B) => {
+  // score a against b,
+  // a, b are str8 up matricies
+}
+
+export default function Correlate(){
+  Hunkify(this)
+
+  let imgIn = this.input('ImageData', 'frame')
+  let imgOut = this.output('ImageData', 'correlation')
+
+  let canvasA = $('<canvas>').get(0)
+  let ctxA = canvasA.getContext('2d')
+  ctxA.width = 100
+  ctxA.height = 100
+
+  this.dom = $('<div>').get(0)
+
+  this.init = () => {
+  }
+
+  this.onload = () => {
+    $(this.dom).append(canvasA)
+  }
+
+  this.loop = () => {
+    if(imgIn.io() && !imgOut.io()){
+      let img = imgIn.get()
+      // we want to set up a loop for this ... first we need some A: a slice of our img,
+      // since we're just checking against ourselves for now... let's take the middle
+      // to clip, I'll use this canvas context ...
+      // this is kind of surprising positioning inputs, but OK
+      ctxA.putImageData(img, -img.width / 2, -img.height / 2, img.width / 2, img.height / 2, ctxA.height, ctxA.width)
+      let a = ctxA.getImageData(0,0, ctxA.height, ctxA.width)
+      //console.log(a.width, a.height)
+      // and b is our original img,
+      // what's the move here?
+      for(let x = 0; x < img.width - a.width, x ++){
+        for(let y = 0; y < img.height - a.height, y ++){
+
+        }
+      }
+    }
+  }
+}
+
+/*
+let img = imgIn.get()
+let width = img.width
+// to ah grayscale array,
+let gs = []
+let sum = 0
+let avg = 0
+for(let i = 0; i < img.data.length; i += 4){
+  sum = 0
+  sum += img.data[i]
+  sum += img.data[i + 1]
+  sum += img.data[i + 2]
+  avg = sum / 3
+  gs.push(avg) //, avg, avg, 255)
+}
+//let gray = new ImageData(Uint8ClampedArray.from(gs), img.width, img.height)
+//imgOut.put(gray)
+// conv. to grayscale,
+// think we need this img ah grayscale array
+// fft that ...
+*/
diff --git a/hunks/adhoc/fftest.js b/hunks/adhoc/fftest.js
deleted file mode 100644
index edf2e87..0000000
--- a/hunks/adhoc/fftest.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-
-attempt of fft cross correlation for fast tracking / subpixel measurements
-
-*/
-
-import {
-  Hunkify,
-  Input,
-  Output,
-  State
-} from '../hunks.js'
-
-export default function FFTest(){
-  Hunkify(this)
-
-  
-}
diff --git a/hunks/adhoc/webcam.js b/hunks/adhoc/webcam.js
index d4a300e..4cd943f 100644
--- a/hunks/adhoc/webcam.js
+++ b/hunks/adhoc/webcam.js
@@ -43,7 +43,6 @@ export default function RTCWebcam(){
         setTimeout(capture, 2000)
         */
       })
-      console.log(video.videoHeight, video.videoWidth)
     }).catch((err) => {
       console.log('get user stream error', err)
     })
diff --git a/save/contexts/cuttlefish/correlate.json b/save/contexts/cuttlefish/correlate.json
new file mode 100644
index 0000000..8e3bb97
--- /dev/null
+++ b/save/contexts/cuttlefish/correlate.json
@@ -0,0 +1,82 @@
+{
+  "interpreterName": "cuttlefish",
+  "interpreterVersion": "v0.1",
+  "hunks": [
+    {
+      "type": "manager",
+      "name": "nrol",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "1",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "view",
+      "name": "tlview",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "0",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "adhoc/webcam",
+      "name": "adhoc/webcam_2",
+      "outputs": [
+        {
+          "name": "frame",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "3",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "adhoc/correlate",
+      "name": "adhoc/correlate_3",
+      "inputs": [
+        {
+          "name": "frame",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "correlation",
+          "type": "ImageData"
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/save/systems/fft.json b/save/systems/fft.json
new file mode 100644
index 0000000..b9c8ef9
--- /dev/null
+++ b/save/systems/fft.json
@@ -0,0 +1,98 @@
+{
+  "interpreterName": "cuttlefish",
+  "interpreterVersion": "v0.1",
+  "hunks": [
+    {
+      "type": "manager",
+      "name": "nrol",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "1",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "view",
+      "name": "tlview",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "0",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "adhoc/webcam",
+      "name": "adhoc/webcam_2",
+      "outputs": [
+        {
+          "name": "frame",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "4",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "image/displayimagedata",
+      "name": "image/displayimagedata_4",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ]
+    },
+    {
+      "type": "adhoc/fftest",
+      "name": "adhoc/fftest_5",
+      "inputs": [
+        {
+          "name": "frame",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "fft",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "3",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
-- 
GitLab