Uses 652K of libraries. Click here for Pure Java version (10695L/62K).
1 | // see https://nanonets.com/blog/optical-flow/ |
2 | |
3 | srecord noeq GoodThingsToTrack(BWImage image) { |
4 | settable int windowSize = 3; |
5 | settable double scoreFactor = 1/256.0; |
6 | gettable BWImage outputImage; |
7 | |
8 | gettable double maxScore; |
9 | |
10 | run { |
11 | int w = image.getWidth(), h = image.getHeight(); |
12 | int wn = windowSize*windowSize; |
13 | int ofs = (windowSize+1)/2; |
14 | outputImage = new BWImage(w, h); |
15 | for (int y = 1; y < h-windowSize-1; y++) { |
16 | for (int x = 1; x < w-windowSize-1; x++) { |
17 | double[] ix = new[wn]; |
18 | double[] iy = new[wn]; |
19 | int iw = 0; |
20 | for yy to windowSize: |
21 | for xx to windowSize: { |
22 | //double value = image.getInt(x+xx, y+yy); |
23 | double left = image.getInt(x+xx-1, y+yy); |
24 | double right = image.getInt(x+xx+1, y+yy); |
25 | double above = image.getInt(x+xx, y+yy-1); |
26 | double below = image.getInt(x+xx, y+yy+1); |
27 | //ix[iw] = right-value; |
28 | //iy[iw] = below-value; |
29 | ix[iw] = right-left; |
30 | iy[iw] = below-above; |
31 | iw++; |
32 | } |
33 | |
34 | double sideSum = 0; |
35 | for i to wn: sideSum += ix[i]*iy[i]; |
36 | double xSum = 0; |
37 | for i to wn: xSum += sqr(ix[i]); |
38 | double ySum = 0; |
39 | for i to wn: ySum += sqr(iy[i]); |
40 | double[][] matrix = new double[][] |
41 | { { xSum, sideSum }, { sideSum, ySum } }; |
42 | Complex[] lambdas = eigenvaluesOfSymmetricMatrix(matrix); |
43 | if (l(lambdas) == 2) { |
44 | double score = min(abs(lambdas[0]), abs(lambdas[1])); |
45 | if (score > maxScore) maxScore = score; |
46 | outputImage.setInt(x+ofs, y+ofs, iround(score*scoreFactor)); |
47 | } |
48 | } |
49 | } |
50 | } |
51 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035325 |
Snippet name: | GoodThingsToTrack [dev.] |
Eternal ID of this version: | #1035325/8 |
Text MD5: | a5bacde6d91a76c47172e0b8f1b97e32 |
Transpilation MD5: | 77276ef832516f30c973e61acfc5852b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-01 04:16:51 |
Source code size: | 1755 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 165 / 264 |
Version history: | 7 change(s) |
Referenced in: | [show references] |