Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
jackie840129 committed Jul 6, 2018
1 parent 6f08fa7 commit 2670b2a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
94 changes: 94 additions & 0 deletions Doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import cv2
import numpy as np

## Load image
img = cv2.imread('Lenna.jpg') ## BGR
## Grayscale
img = cv2.imread('Lenna.jpg',0)

## Show image
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

## Save image
cv2.imwrite('test.jpg',img)

## Show image with matplotlib
import matplotlib.pyplot as plt
plt.imshow(img[:,:,::-1]) ## To RGB
plt.show()

plt.imshow(img,cmap='gray')
plt.show()

#-----------------Lab1-----------------------
## Resize
cv2.resize()
## Color space
cv2.cvtColor()
## smoothing
cv2.blur(),cv2.GaussianBlur(),cv2.mediaBlur()
## PCA Compute
mean,eigenvectors = cv2.PCACompute(matrix,mean=None)

## min, max
np.min(), np.max()
## dot
np.dot()
## flatten
np.flatten()

## KNN
from sklearn.neighbors import KNeighborsClassifier
# 宣告
KNN = KNeighborsClassifier(args)
# Feed Training Data
KNN.fit(X_train,Y_train)
# Predict Class
KNN.predict(X_test)
# 直接告訴你acc
KNN.score(X_test,Y_test)

#-----------------Lab2-----------------------
## Opencv
# ColorMap
cv2.applyColorMap()
# Padding
cv2.copyMakeBorder() #use cv2.BORDER_REFLECT
# SURF
cv2.xfeatures2d.SURF_create()
cv2.drawKeyPoints()

## Numpy scipy
# Save & load
np.save(),np.load()
# concatenate
np.concatenate()
# mean
np.mean()
# reciprocal
np.reciprocal()
# load .mat file
import scipy.io as sio
sio.loadmat()
# Euclidean distance
from scipy.spatial import distance
distance.euclidean()

## Sklearn
# Kmeans
from sklearn.cluster import KMeans
Kmeans = KMeans(args)
Kmeans.fit_predict(X)

## Matplotlib
import matplotlib.pyplot as plt
plt.figure()
plt.bar(x,y)
plt.title()
plt.xlabel()
plt.ylabel()
plt.savefig()


Binary file added Introduction.pdf
Binary file not shown.
6 changes: 4 additions & 2 deletions Lab_2/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ for simplicity). The centroid of each cluster then indicates a visual word.

<img src="./image/hardsum.jpg" alt="hs" width="280px"/> <img src="./image/softsum.jpg" alt="ss" width="280px" /> <img src="./image/softmax.jpg" alt="sm" width="280px"/>

4. ) Finally, We adopt the k-nearest neighbors classifier (**KNN**) to perform classification
**hint** : You can use `matplotlib.pyplot.bar()` to plot the figure

4. Finally, We adopt the k-nearest neighbors classifier (**KNN**) to perform classification
using the above BoW features.

Use Train-100 as the training data and Test-100 for testing (you may choose k = 3
for simplicity). Report the classification accuracy using **Hard-Sum**, **Soft-Sum**, and
**Soft-Max**. Are the results as expected (based on your observation on different BoW
features in 3.)? If not, why?
features in 3.? If not, why?
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This Python Opencv Lab is split into two parts for morning and afternoon.
1. [Lab_1/](./Lab_1) : Image Operation, Image Smoothing, Image Denoising, Image PCA & Classification
2. [Lab_2/](./Lab_2) : Color and Texture Segmentation (Clustering) , Recognition with Bag of Visual Words

### Briefly Introdiction

[Introduction.pdf](./Introduction.pdf)

### Reference
The lab practice referred to [OpenCVtutorial](http://opencv-python-tutroals.readthedocs.io/en/latest/index.html) and NTU Deep Learning for Computer Vision (DLCV) course [website](http://vllab.ee.ntu.edu.tw/dlcv.html).

Expand Down

0 comments on commit 2670b2a

Please sign in to comment.