Ask Your Question
0

Watershed Transform and PCA opencv 3.0 c++ [closed]

asked 2016-12-29 00:34:21 -0600

Allison gravatar image

updated 2016-12-29 01:37:10 -0600

I am trying to train a PCA(classification/recognition) with watershed transform(feature extraction) on Opencv 3.0 with C++. I have managed to get the watershed working but now I have trouble merging the watershed transform with the PCA.

Can Watershed algorithm be performed with PCA for training data?

Here is my output as watershedded image.

image description

Now i want to use it with PCA for activity recognition,that is, six different types of activities (named: bend, jack, run, side, skip, and wave) have to be recognized.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Allison
close date 2017-01-18 03:03:51.240879

Comments

1

what is the output of your transform, and how do you plan to apply a PCA on that ?

berak gravatar imageberak ( 2016-12-29 01:16:48 -0600 )edit

thanks for the nice update above.

you'll probably need some machine-learning for the classification, so this is meant as a preprocessing/filtering step, right ?

do you want to reduce the feature space with the PCA ? (like "eigen-actions" ?)

berak gravatar imageberak ( 2016-12-29 02:34:07 -0600 )edit
1

@berak right as the preprocessing stage. Yes I want to reduce the dimensionality of the feature space with PCA

Allison gravatar imageAllison ( 2016-12-29 03:05:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-12-29 03:02:34 -0600

berak gravatar image

updated 2016-12-29 04:56:13 -0600

if you want to use PCA to "compress" your train data set, you will need a single Mat with each image flattened to a row. all images need to be the same size here(also i'd suggest, you crop and resize an image like above to something smaller, like 150x150, else your PCA will take ages !):

Mat td;
for (image : trainset) {
    image.convertTo(image, CV_32F); // we need float data
    td.push_back(image.reshape(1,1)); // flat row 
}

now you can build the PCA:

int num_components = 500; // how many features to retain    
PCA pca(td, Mat(), cv::PCA::DATA_AS_ROW, num_components);

this will take a while, after it finished, you can project your train data to PCA space (this is, where the actual reduction happens !)

Mat trainData; // for ml, now
for (image : trainset) {
    image.convertTo(image, CV_32F); // we need float data
    Mat projected = pca.project(image.reshape(1,1)); // flat row 
    trainData.push_back(projected); // reduced to num_components features
}

later, for testing, you'll do the same reduction, so you have to keeep the "trained" PCA object around:

image.convertTo(image, CV_32F); // we need float data
Mat projected = pca.project(image.reshape(1,1)); // flat row, reduced to num_components  
ml->predict(projected);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-29 00:34:21 -0600

Seen: 287 times

Last updated: Dec 29 '16