Ask Your Question
-1

Reducing dimensionality of ORB descriptor with PCA [CLOSED]

asked 2019-03-07 15:29:39 -0600

newlearner1994 gravatar image

updated 2019-03-09 07:49:28 -0600

i try to reduce dimensionality of feature that have been extracted by using ORB with PCA then draw the keypoints that processed by PCA

e1 = cv2.getTickCount()
#read image and convert to RGB
image_normal = cv2.imread(image)
image_query = cv2.cvtColor(image_normal, cv2.COLOR_BGR2RGB)
image_gray  = cv2.cvtColor(image_query, cv2.COLOR_RGB2GRAY)

#ORB function
orb = cv2.ORB_create()
keypoints, descriptor = orb.detectAndCompute(image_gray, None)

# Draw the keypoints 
image = cv2.drawKeypoints(image_query, keypoints,0,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
mean, eigenvectors = cv2.PCACompute(image, np.mean(image, axis=0).reshape(1,-1))          

e2 = cv2.getTickCount()
t = (e2 - e1) / cv2.getTickFrequency() 

#Show Image
plt.imshow(image)
plt.title('ORB Keypoints')
plt.show()

# Print the number of keypoints detected and time
print("\nNumber of keypoints Detected: ", len(keypoints))
print('Time Cost for ORB: ', (t))

as i try i got an error that says

error: OpenCV(3.4.2) C:\projects\opencv- python\opencv\modules\core\src\pca.cpp:72: error: (-215:Assertion failed) data.channels() == 1 in function 'cv::PCA::operator ()'
edit retag flag offensive close merge delete

Comments

i try to reduce dimensionality of feature that have been extracted by using ORB with PCA then draw the keypoints

but what you did instead was: draw the keypoints to an image and to take the pca from that (and that's bs)

and no, you can't apply a PCA on ORB features, which are binary, bitstrings

berak gravatar imageberak ( 2019-03-07 15:43:05 -0600 )edit
1

thank you for replying, i'm really new to computer vision,

i read in some thread about PCA SIFT,

can PCA used to reduce feature, if can would you be kind and give an example,

i'm sorry if i sound like a choosing beggar

thank you in advance sir

newlearner1994 gravatar imagenewlearner1994 ( 2019-03-07 15:56:47 -0600 )edit

indeed, SIFT and SURF are float descriptors (suitable for PCA), while BRISK,BRIEF,ORB are examples for binary ones (no PCA possible)

berak gravatar imageberak ( 2019-03-07 16:06:55 -0600 )edit

wow thank you for that information sir, so how can PCA be used on SIFT or SURF, and besides ORB that obviously wrong, how to implement PCA my in code above?

newlearner1994 gravatar imagenewlearner1994 ( 2019-03-07 16:39:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-08 02:17:49 -0600

berak gravatar image

updated 2019-03-09 05:49:23 -0600

well, again, you need float descriptors / data, and, since you're trying to find out the statistically most relevant features, you need a "representive set" (aka "a lot of data", from many images):

// step 1, offline
Mat a_lot_of_features = ....                   // (say 10000 rows, 128 cols, FLOAT!!!)
PCA pca(a_lot_of_features, Mat(), 0, 64);      // keep e.g. the 64 strongest eigenvecs 
cout << pca.eigenvectors.size() << endl;       // [128 x 64]
// keep pca object around, use it to reduce the image_features

// step 2, online
Mat image_features(100, 128, CV_32F);          // e.g. 100 SURF features from an image
Mat projected = pca.project(image_features);   // it will reduce the feature size, not the count !
cout << projected.size() << endl;              // [64 x 100] num_eigenvecs x feature count
// use projected vec instead of original image_features
edit flag offensive delete link more

Comments

ahh i see now, thank you sir, may god bless you

newlearner1994 gravatar imagenewlearner1994 ( 2019-03-08 14:59:38 -0600 )edit

for python, you want to keep the eigenvectors, and use PCAproject()

berak gravatar imageberak ( 2019-03-09 05:46:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-07 15:29:39 -0600

Seen: 888 times

Last updated: Mar 09 '19