This notebook uses the Accord library for math, statistics, vision, and machine learning. It should be split up into many notebooks, but this is currently for testing.
from System import Array
import Accord
import Accord.Math
import clr
clr.ImportExtensions(Accord.Math)
Accord.Math.Matrix.Indices(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
from Accord.Math import Matrix
v = Matrix.Identity(3)
v
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
I = Array.CreateInstance(float, 2, 2)
I[0,0] = 1
I
[[1, 0], [0, 0]]
u = Array[float]([1, 6])
v = Array[float]([-2, 10])
u.InnerProduct(v)
58
outer = u.OuterProduct(v)
outer
[[-2, 10], [-12, 60]]
I.Multiply(u)
[1, 0]
I.Multiply(v)
[-2, 0]
from Accord.Math.Decompositions import SingularValueDecomposition
i = SingularValueDecomposition(I)
i.Diagonal
[1, 0]
from Processing import *
size(500, 500)
background(0)
smooth()
points = []
def drawPoint():
fill(255, 0, 0)
noStroke()
points.append([mouseX(), mouseY()])
ellipse(mouseX(), mouseY(), 5, 5)
onMouseDragged += drawPoint
loop()
def clear():
global points
points = []
background(0)
onKeyPressed += clear
points
[[95.0, 249.0], [95.0, 249.0], [99.0, 249.0], [99.0, 249.0], [104.0, 247.0], [104.0, 247.0], [111.0, 242.0], [111.0, 242.0], [116.0, 238.0], [116.0, 238.0], [121.0, 234.0], [121.0, 234.0], [125.0, 232.0], [125.0, 232.0], [130.0, 228.0], [130.0, 228.0], [137.0, 224.0], [137.0, 224.0], [146.0, 220.0], [146.0, 220.0], [151.0, 215.0], [151.0, 215.0], [156.0, 211.0], [156.0, 211.0], [162.0, 207.0], [162.0, 207.0], [173.0, 201.0], [173.0, 201.0], [186.0, 193.0], [186.0, 193.0], [195.0, 187.0], [195.0, 187.0], [203.0, 181.0], [203.0, 181.0], [213.0, 176.0], [213.0, 176.0], [224.0, 171.0], [224.0, 171.0], [237.0, 162.0], [237.0, 162.0], [251.0, 153.0], [251.0, 153.0], [261.0, 150.0], [261.0, 150.0], [269.0, 144.0], [269.0, 144.0], [277.0, 140.0], [277.0, 140.0], [287.0, 135.0], [287.0, 135.0], [297.0, 129.0], [297.0, 129.0], [304.0, 125.0], [304.0, 125.0], [308.0, 123.0], [308.0, 123.0], [318.0, 120.0], [318.0, 120.0], [326.0, 120.0], [326.0, 120.0], [339.0, 120.0], [339.0, 120.0], [347.0, 120.0], [347.0, 120.0], [353.0, 120.0], [353.0, 120.0], [356.0, 120.0], [356.0, 120.0], [358.0, 120.0], [358.0, 120.0], [361.0, 120.0], [361.0, 120.0], [363.0, 120.0], [363.0, 120.0], [363.0, 119.0], [363.0, 119.0], [178.0, 323.0], [178.0, 323.0], [180.0, 319.0], [180.0, 319.0], [185.0, 316.0], [185.0, 316.0], [190.0, 311.0], [190.0, 311.0], [195.0, 306.0], [195.0, 306.0], [202.0, 300.0], [202.0, 300.0], [212.0, 291.0], [212.0, 291.0], [222.0, 283.0], [222.0, 283.0], [236.0, 272.0], [236.0, 272.0], [248.0, 260.0], [248.0, 260.0], [257.0, 252.0], [257.0, 252.0], [267.0, 240.0], [267.0, 240.0], [283.0, 228.0], [283.0, 228.0], [299.0, 216.0], [299.0, 216.0], [309.0, 208.0], [309.0, 208.0], [318.0, 196.0], [318.0, 196.0], [325.0, 192.0], [325.0, 192.0], [331.0, 188.0], [331.0, 188.0], [336.0, 188.0], [336.0, 188.0], [341.0, 188.0], [341.0, 188.0], [344.0, 188.0], [344.0, 188.0], [348.0, 188.0], [348.0, 188.0], [353.0, 188.0], [353.0, 188.0], [357.0, 188.0], [357.0, 188.0], [361.0, 188.0], [361.0, 188.0], [361.0, 188.0], [361.0, 188.0], [359.0, 232.0], [359.0, 232.0], [359.0, 234.0], [359.0, 234.0], [359.0, 235.0], [359.0, 235.0], [360.0, 239.0], [360.0, 239.0], [363.0, 245.0], [363.0, 245.0], [365.0, 252.0], [365.0, 252.0], [368.0, 258.0], [368.0, 258.0], [370.0, 262.0], [370.0, 262.0], [373.0, 269.0], [373.0, 269.0], [375.0, 274.0], [375.0, 274.0], [375.0, 277.0], [375.0, 277.0], [376.0, 277.0], [376.0, 277.0], [376.0, 277.0], [376.0, 277.0], [379.0, 281.0], [379.0, 281.0], [381.0, 284.0], [381.0, 284.0], [383.0, 288.0], [383.0, 288.0], [383.0, 290.0], [383.0, 290.0], [384.0, 290.0], [384.0, 290.0], [385.0, 294.0], [385.0, 294.0], [385.0, 295.0], [385.0, 295.0], [385.0, 294.0], [385.0, 294.0], [385.0, 295.0], [385.0, 295.0], [402.0, 332.0], [402.0, 332.0], [404.0, 335.0], [404.0, 335.0], [405.0, 339.0], [405.0, 339.0], [407.0, 343.0], [407.0, 343.0], [411.0, 348.0], [411.0, 348.0], [416.0, 355.0], [416.0, 355.0], [419.0, 361.0], [419.0, 361.0], [423.0, 367.0], [423.0, 367.0], [427.0, 373.0], [427.0, 373.0], [429.0, 377.0], [429.0, 377.0], [431.0, 381.0], [431.0, 381.0], [433.0, 383.0], [433.0, 383.0], [433.0, 384.0], [433.0, 384.0], [433.0, 385.0], [433.0, 385.0], [434.0, 385.0], [434.0, 385.0], [434.0, 386.0], [434.0, 386.0], [434.0, 387.0], [434.0, 387.0], [435.0, 389.0], [435.0, 389.0], [435.0, 390.0], [435.0, 390.0], [435.0, 391.0], [435.0, 391.0], [435.0, 392.0], [435.0, 392.0], [461.0, 439.0], [461.0, 439.0], [461.0, 440.0], [461.0, 440.0], [461.0, 441.0], [461.0, 441.0], [462.0, 444.0], [462.0, 444.0], [465.0, 448.0], [465.0, 448.0], [466.0, 452.0], [466.0, 452.0], [468.0, 456.0], [468.0, 456.0], [471.0, 461.0], [471.0, 461.0], [474.0, 463.0], [474.0, 463.0], [476.0, 466.0], [476.0, 466.0], [478.0, 470.0], [478.0, 470.0], [480.0, 475.0], [480.0, 475.0], [482.0, 477.0], [482.0, 477.0], [482.0, 478.0], [482.0, 478.0], [482.0, 479.0], [482.0, 479.0], [482.0, 479.0], [482.0, 479.0]]
data = Array.CreateInstance(float, len(points), len(points[0]))
for i in range(len(points)):
for j in range(len(points[i])):
data[i,j] = points[i][j]
print("# of points: ", data.Length)
from Accord.Statistics.Analysis import *
analysis = DescriptiveAnalysis(data)
ux,uy = analysis.Means
pca = PrincipalComponentAnalysis(data, AnalysisMethod.Center)
# Compute the Principal Component Analysis
pca.Compute()
stroke(0, 255,0)
strokeWeight(5)
for pc in pca.Components:
x,y = pc.Eigenvector.Multiply(pc.Eigenvalue**0.5)
line(ux - x, uy - y, ux + x, uy + y)
# of points: 492
get()
for v in analysis.CovarianceMatrix:
print(v)
11580.2068027 6510.53333333 6510.53333333 11027.7245728
from AForge.Imaging.Filters import *
from Accord.Imaging.Filters import *
from AForge.Imaging import Image
from Graphics import *
from System.Drawing import Bitmap
from System.Drawing.Imaging import PixelFormat
p = Picture("http://roboteducation.org/images/header_home.jpg")
image = p.toBitmap() #Image.Clone(p.toBitmap(), PixelFormat.Format24bppRgb)
calico.display(p)
# Create a new Gabor filter
filter = GaborFilter()
# Apply the filter
output = filter.Apply(image)
calico.display(Picture(output))
filter = GaussianBlur( 4, 11 )
output = filter.Apply( image )
calico.display(Picture(image))
calico.display(Picture(output))
import AForge.Imaging
dir(AForge.Imaging)
['Blob', 'BlobCounter', 'BlobCounterBase', 'BlockMatch', 'ColorReduction', 'ComplexFilters', 'ComplexImage', 'DocumentSkewChecker', 'Drawing', 'ExhaustiveBlockMatching', 'ExhaustiveTemplateMatching', 'Filters', 'HSL', 'HorizontalIntensityStatistics', 'HoughCircle', 'HoughCircleTransformation', 'HoughLine', 'HoughLineTransformation', 'IBlobsFilter', 'IBlockMatching', 'ICornersDetector', 'ITemplateMatching', 'Image', 'ImageStatistics', 'ImageStatisticsHSL', 'ImageStatisticsYCbCr', 'IntegralImage', 'InvalidImagePropertiesException', 'MemoryManager', 'MoravecCornersDetector', 'ObjectsOrder', 'QuadrilateralFinder', 'RGB', 'RecursiveBlobCounter', 'SusanCornersDetector', 'TemplateMatch', 'Textures', 'UnmanagedImage', 'UnsupportedImageFormatException', 'VerticalIntensityStatistics', 'YCbCr']
grayimage = Grayscale( 0.2125, 0.7154, 0.0721 ).Apply(image)
calico.display(Picture(grayimage))
filter = Threshold( 100 )
bwimage = filter.Apply( grayimage )
calico.display(Picture(bwimage))
from Accord.Imaging.Filters import RobinsonEdgeDetector
robinson = RobinsonEdgeDetector()
edges = robinson.Apply(image)
calico.display(Picture(edges))
from Accord.Imaging import SpeededUpRobustFeaturesDetector
from Accord.Imaging.Filters import FeaturesMarker
surf = SpeededUpRobustFeaturesDetector(.005, 5, 1)
points = surf.ProcessImage(image)
features = FeaturesMarker(points);
#new = features.Apply(grayimage)
#calico.display(Picture(new))
len(points)
157
import System
try:
new = features.Apply(grayimage)
except System.Exception, e:
print(e)
System.Exception: Generic Error [GDI+ status: GenericError] at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 at System.Drawing.Graphics.DrawEllipse (System.Drawing.Pen pen, Int32 x, Int32 y, Int32 width, Int32 height) [0x00000] in <filename unknown>:0 at (wrapper remoting-invoke-with-check) System.Drawing.Graphics:DrawEllipse (System.Drawing.Pen,int,int,int,int) at Accord.Imaging.Filters.FeaturesMarker.ProcessFilter (AForge.Imaging.UnmanagedImage sourceData, AForge.Imaging.UnmanagedImage destinationData) [0x00000] in <filename unknown>:0 at AForge.Imaging.Filters.BaseFilter.Apply (System.Drawing.Imaging.BitmapData imageData) [0x00000] in <filename unknown>:0 at AForge.Imaging.Filters.BaseFilter.Apply (System.Drawing.Bitmap image) [0x00000] in <filename unknown>:0 at (wrapper delegate-invoke) <Module>:invoke_callvirt_Bitmap_BaseFilter_Bitmap (AForge.Imaging.Filters.BaseFilter,System.Drawing.Bitmap) at Microsoft.Scripting.Interpreter.FuncCallInstruction`3[AForge.Imaging.Filters.BaseFilter,System.Drawing.Bitmap,System.Drawing.Bitmap].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0 at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0
from Graphics import *
from Myro import show
v = Picture(image)
w = Window(v.width, v.height)
w.draw(v)
for j in points:
c = Circle((j.X, j.Y), 2)
c.color = Color("red")
w.draw(c)
calico.display(w)
from Accord.Vision.Detection import *
from Accord.Vision.Detection.Cascades import *
cascade = FaceHaarCascade()
detector = HaarObjectDetector(cascade, 15)
points = detector.ProcessFrame(image)
for j in points:
c = Rectangle((j.X, j.Y), (j.X + j.Width, j.Y + j.Height))
c.outline = Color("green")
c.fill = None
w.draw(c)
calico.display(w)