This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(randomForest) | |
#「フィッシャーのあやめ」データセットを読み出す | |
data(iris) | |
#データセットを特徴量とラベルに分割 | |
features<-iris[1:4] | |
labels<-iris[5] | |
#ラベルを因子化 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setosa versicolor virginica MeanDecreaseAccuracy MeanDecreaseGini | |
Sepal.Length 7.277437 7.0994514 8.087167 10.842432 9.553025 | |
Sepal.Width 5.029336 -0.4402422 2.381594 3.438372 2.528796 | |
Petal.Length 22.909121 32.9889332 30.209000 35.201262 43.785432 | |
Petal.Width 21.741775 30.5797963 31.309059 32.724397 43.400080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
class BagOfFeatures: | |
"""This is a class of Bag-of-Features by K-means for OpenCV""" | |
codebookSize=0 | |
classifier=None | |
def __init__(self, codebookSize): | |
self.codebookSize=codebookSize | |
self.classifier=cv2.KNearest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#see also: http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html | |
import numpy as np | |
from sklearn import mixture,preprocessing | |
class BagOfFeaturesGMM: | |
"""This is a class of Bag-of-Features by GMM """ | |
codebookSize=0 | |
classifier=None | |
def __init__(self, codebookSize): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Mat image=cv::imread("./image.png",-1); | |
cv::Rect rect(startColumn,startRow,image.cols,image.rows); | |
cv::Mat subdst=dst(rect); | |
image.copyTo(subdst); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Mat image=cv::imread("./image.png",-1); | |
cv::Mat trans=cv::imread("./trans.png",0); | |
cv::Rect rect1(startColumn1,startRow1,trans.cols,trans.rows); | |
cv::Mat subdst1=dst(rect1); | |
trans.convertTo(subdst1,subdst1.type(),alpha);//double alphaは透過率[0.0, 1.0] | |
cv::Rect rect2(startColumn2,startRow2,image.cols,image.rows); | |
cv::Mat subdst2=dst(rect2); | |
image.copyTo(subdst2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Mat image=cv::imread("./image.png",-1); | |
cv::Mat image_mask=cv::imread("./mask.png",0); | |
cv::Rect rect(startColumn,startRow,image.cols,image.rows); | |
cv::Mat subdst=dst(rect); | |
image.copyTo(subdst,image_mask); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#BoF(SIFT)により一般物体認識を行うサンプルコード | |
#今回はイルカと象を識別 | |
#評価用のデータセットとしてCaltech 101を使用 | |
#see also: http://www.vision.caltech.edu/Image_Datasets/Caltech101/ | |
import cv2 | |
import numpy as np | |
from sklearn import svm | |
from sklearn import cross_validation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ave. score(BagOfFeatures):70.492308[%] | |
Ave. score(BagOfFeaturesGMM):71.323077[%] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Its behavior is like hash (associative array). | |
hash.test=list("square"=function(x){x**2}, | |
"pi"=3.1415926535) | |
hash.test[["square"]](2) | |
hash.test[["pi"]] | |
#probability that a random selected number is a prime number. | |
6/hash.test[["square"]](hash.test[["pi"]]) |
OlderNewer