本文整理汇总了Java中gr.iti.mklab.visual.vectorization.ImageVectorization类的典型用法代码示例。如果您正苦于以下问题:Java ImageVectorization类的具体用法?Java ImageVectorization怎么用?Java ImageVectorization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageVectorization类属于gr.iti.mklab.visual.vectorization包,在下文中一共展示了ImageVectorization类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: VisualIndexerBolt
点赞 3
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public VisualIndexerBolt(String webServiceHost, String indexCollection, String[] codebookFiles, String pcaFile) throws Exception {
_webServiceHost = webServiceHost;
_indexCollection = indexCollection;
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
if(initialLength > targetLengthMax) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
}
开发者ID:socialsensor,
项目名称:storm-focused-crawler,
代码行数:21,
代码来源:VisualIndexerBolt.java
示例2: FeatureExtractorBolt
点赞 3
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public FeatureExtractorBolt(String webServiceHost, String indexCollection, String[] codebookFiles, String pcaFile) throws Exception {
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
if(initialLength > targetLengthMax) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
}
开发者ID:socialsensor,
项目名称:storm-focused-crawler,
代码行数:17,
代码来源:FeatureExtractorBolt.java
示例3: VisualIndexer
点赞 3
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public VisualIndexer(String webServiceHost, String indexCollection, String[] codebookFiles, String pcaFile) throws Exception {
this.webServiceHost = webServiceHost;
this.indexCollection = indexCollection;
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:18,
代码来源:VisualIndexer.java
示例4: MediaItemsVisualIndexer
点赞 3
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
MediaItemsVisualIndexer(String host, String dbname, String collectionName,
String webServiceHost, String indexCollection, String[] codebookFiles, String pcaFile)
throws Exception {
this.mongo = new MongoClient(host);
this.db = mongo.getDB(dbname);
this.input_collection = db.getCollection(collectionName);
input_collection.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
this.visualIndexHandler = new VisualIndexHandler(webServiceHost, indexCollection);
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:23,
代码来源:MediaItemsVisualIndexer.java
示例5: VisualIndexerBolt
点赞 3
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public VisualIndexerBolt(String webServiceHost, String indexCollection, String[] codebookFiles, String pcaFile) throws Exception {
this.webServiceHost = webServiceHost;
this.indexCollection = indexCollection;
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
if(initialLength > targetLengthMax) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:20,
代码来源:VisualIndexerBolt.java
示例6: VisualIndex
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public VisualIndex(String learningFolder, String indexFolder) throws Exception {
int maximumNumVectors = 20000;
int m = 128, k_c = 256, numCoarseCentroids = 8192;
String[] codebookFiles = {
learningFolder + "surf_l2_128c_0.csv",
learningFolder + "surf_l2_128c_1.csv",
learningFolder + "surf_l2_128c_2.csv",
learningFolder + "surf_l2_128c_3.csv"
};
String pcaFile = learningFolder + "pca_surf_4x128_32768to1024.txt";
String coarseQuantizerFile = learningFolder + "qcoarse_1024d_8192k.csv";
String productQuantizerFile = learningFolder + "pq_1024_128x8_rp_ivf_8192k.csv";
ImageVectorization.setFeatureExtractor(new SURFExtractor());
ImageVectorization.setVladAggregator(new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids, AbstractFeatureExtractor.SURFLength));
if (targetLengthMax < initialLength) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
String linearIndexFolder = indexFolder + "/linear";
String ivfpqIndexFolder = indexFolder + "/ivfpq";
this.linearIndex = new Linear(targetLengthMax, maximumNumVectors, false, linearIndexFolder, true, true, 0);
this.ivfpqIndex = new IVFPQ(targetLength, maximumNumVectors, false, ivfpqIndexFolder, m, k_c, PQ.TransformationType.RandomPermutation, numCoarseCentroids, true, 0);
ivfpqIndex.loadCoarseQuantizer(coarseQuantizerFile);
ivfpqIndex.loadProductQuantizer(productQuantizerFile);
ivfpqIndex.setW(128); // how many (out of 8192) lists should be visited during search.
}
开发者ID:MKLab-ITI,
项目名称:mgraph-summarization,
代码行数:38,
代码来源:VisualIndex.java
示例7: index
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public void index(List<Item> items) throws IOException {
for(Item item : items) {
Map<String, String> mediaItems = item.getMediaItems();
for(Entry<String, String> mi : mediaItems.entrySet()) {
String mediaId = mi.getKey();
String mediaUrl = mi.getValue();
try {
URL url = new URL(mediaUrl);
byte[] content = IOUtils.toByteArray(url);
BufferedImage img = ImageIO.read(new ByteArrayInputStream(content));
ImageVectorization imvec = new ImageVectorization(mediaId, img , targetLengthMax, maxNumPixels);
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
// the full vector is indexed in the disk-based index
linearIndex.indexVector(mediaId, vector);
// the vector is truncated to the correct dimension and renormalized before sending to the ram-based index
double[] newVector = Arrays.copyOf(vector, targetLength);
if (newVector.length < vector.length) {
Normalization.normalizeL2(newVector);
}
ivfpqIndex.indexVector(mediaId, newVector);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
开发者ID:MKLab-ITI,
项目名称:mgraph-summarization,
代码行数:38,
代码来源:VisualIndex.java
示例8: IndexingManager
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
private IndexingManager() {
try {
int[] numCentroids = {128, 128, 128, 128};
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
String[] codebookFiles = {
learningFolder + "surf_l2_128c_0.csv",
learningFolder + "surf_l2_128c_1.csv",
learningFolder + "surf_l2_128c_2.csv",
learningFolder + "surf_l2_128c_3.csv"
};
String pcaFile = learningFolder + "pca_surf_4x128_32768to1024.txt";
//visualIndex = new Linear(targetLengthMax, 10000000, false, BDBEnvHome, false, false, 0);
//int existingVectors = visualIndex.getLoadCounter();
SURFExtractor extractor = new SURFExtractor();
ImageVectorization.setFeatureExtractor(extractor);
double[][][] codebooks = AbstractFeatureAggregator.readQuantizers(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(new VladAggregatorMultipleVocabularies(codebooks));
if (targetLengthMax < initialLength) {
System.out.println("targetLengthMax : " + targetLengthMax + " initialLengh " + initialLength);
pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
} catch (Exception ex) {
//TODO: do something
}
}
开发者ID:kandreadou,
项目名称:reveal-web-service,
代码行数:33,
代码来源:IndexingManager.java
示例9: indexImage
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public boolean indexImage(String imageFolder, String imageFilename, String collection) throws Exception {
if (Strings.isNullOrEmpty(collection)) {
collection = DEFAULT_COLLECTION_NAME;
}
AbstractSearchStructure index = indices.get(collection);
if (index == null) {
createIndex(collection);
index = indices.get(collection);
}
ImageVectorization imvec = new ImageVectorization(imageFolder, imageFilename, targetLengthMax, maxNumPixels);
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
return index.indexVector(imageFilename, vector);
}
开发者ID:kandreadou,
项目名称:reveal-web-service,
代码行数:16,
代码来源:IndexingManager.java
示例10: findSimilar
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public Answer findSimilar(String url, String collection, int neighbours) throws Exception {
if (Strings.isNullOrEmpty(collection)) {
collection = DEFAULT_COLLECTION_NAME;
}
AbstractSearchStructure index = indices.get(collection);
if (index == null) {
createIndex(collection);
index = indices.get(collection);
}
BufferedImage img = ImageIO.read(new URL(url));
ImageVectorization imvec = new ImageVectorization(url, img, targetLengthMax, maxNumPixels);
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
return index.computeNearestNeighbors(neighbours, vector);
}
开发者ID:kandreadou,
项目名称:reveal-web-service,
代码行数:16,
代码来源:IndexingManager.java
示例11: initialize
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
private void initialize(Context context) throws Exception {
int[] numCentroids = {128, 128, 128, 128};
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
/*if (!VisualJob.IS_LOCAL) {
Path files[] = DistributedCache.getLocalCacheFiles(context.getConfiguration());
for (Path path : files) {
context.write(new Text(path.toString() + " " + path.getName()), new DoubleArrayWritable(new double[0]));
}
}*/
String[] codebookFiles = {
VisualJob.LEARNING_FILES_PATH + "surf_l2_128c_0.csv",
VisualJob.LEARNING_FILES_PATH + "surf_l2_128c_1.csv",
VisualJob.LEARNING_FILES_PATH + "surf_l2_128c_2.csv",
VisualJob.LEARNING_FILES_PATH + "surf_l2_128c_3.csv"
};
String pcaFile = VisualJob.LEARNING_FILES_PATH + "pca_surf_4x128_32768to1024.txt";
ImageVectorization.setFeatureExtractor(new SURFExtractor());
double[][][] codebooks = AbstractFeatureAggregator.readQuantizers(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(new VladAggregatorMultipleVocabularies(codebooks));
if (targetLengthMax < initialLength) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
// Initialize the downloader, the vectorizer and the indexer
downloader = new ImageDownloader("", numDownloadThreads);
downloader.setSaveOriginal(false);
downloader.setSaveThumb(false);
downloader.setFollowRedirects(false);
vectorizer = new ImageVectorizer("surf", codebookFiles, numCentroids,
targetLengthMax, pcaFile, true, numVectorizationThreads);
}
开发者ID:MKLab-ITI,
项目名称:multimedia-indexing,
代码行数:41,
代码来源:VisualThreadedMapper.java
示例12: index
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public static void index(String directory, String linearIndexFolder, String ivfpqIndexFolder, String learningFolder) throws Exception {
File dir = new File(directory);
if(!dir.isDirectory())
return;
if(!learningFolder.endsWith("/"))
learningFolder += "/";
// parameters
int maxNumPixels = 768 * 512;
int[] numCentroids = { 128, 128, 128, 128 };
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
int targetLengthMax = 1024;
int targetLength = 1024;
int maximumNumVectors = 20000;
int m = 128, k_c = 256, numCoarseCentroids = 8192;
String[] codebookFiles = {
learningFolder + "surf_l2_128c_0.csv",
learningFolder + "surf_l2_128c_1.csv",
learningFolder + "surf_l2_128c_2.csv",
learningFolder + "surf_l2_128c_3.csv"
};
String pcaFile = learningFolder + "pca_surf_4x128_32768to1024.txt";
String coarseQuantizerFile = learningFolder + "qcoarse_1024d_8192k.csv";
String productQuantizerFile = learningFolder + "pq_1024_128x8_rp_ivf_8192k.csv";
ImageVectorization.setFeatureExtractor(new SURFExtractor());
ImageVectorization.setVladAggregator(new VladAggregatorMultipleVocabularies(codebookFiles,
numCentroids, AbstractFeatureExtractor.SURFLength));
if (targetLengthMax < initialLength) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
Linear linear = new Linear(targetLengthMax, maximumNumVectors, false, linearIndexFolder, true, true, 0);
IVFPQ ivfpq_1 = new IVFPQ(targetLength, maximumNumVectors, false, ivfpqIndexFolder, m, k_c, PQ.TransformationType.RandomPermutation, numCoarseCentroids, true, 0);
ivfpq_1.loadCoarseQuantizer(coarseQuantizerFile);
ivfpq_1.loadProductQuantizer(productQuantizerFile);
ivfpq_1.setW(128); // how many (out of 8192) lists should be visited during search.
for(String id : dir.list()) {
System.out.println(id);
ImageVectorization imvec = new ImageVectorization(dir.toString()+"/", id, targetLengthMax, maxNumPixels);
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
// the full vector is indexed in the disk-based index
linear.indexVector(id, vector);
// the vector is truncated to the correct dimension and renormalized before sending to the ram-based index
double[] newVector = Arrays.copyOf(vector, targetLength);
if (newVector.length < vector.length) {
Normalization.normalizeL2(newVector);
}
ivfpq_1.indexVector(id, newVector);
}
}
开发者ID:MKLab-ITI,
项目名称:mgraph-summarization,
代码行数:72,
代码来源:MultimediaHandler.java
示例13: execute
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public void execute(Tuple tuple) {
MediaItem mediaItem = (MediaItem) tuple.getValueByField("MediaItem");
if(mediaItem == null)
return;
HttpGet httpget = null;
ImageVector imageVector = null;
try {
String id = mediaItem.getId();
String type = mediaItem.getType();
String url = type.equals("image") ? mediaItem.getUrl() : mediaItem.getThumbnail();
httpget = new HttpGet(url.replaceAll(" ", "%20"));
httpget.setConfig(_requestConfig);
HttpResponse response = _httpclient.execute(httpget);
StatusLine status = response.getStatusLine();
int code = status.getStatusCode();
if(code<200 || code>=300) {
_logger.error("Failed fetch media item " + id + ". URL=" + url +
". Http code: " + code + " Error: " + status.getReasonPhrase());
mediaItem.setVisualIndexed(false);
_collector.emit(tuple(mediaItem, imageVector));
return;
}
HttpEntity entity = response.getEntity();
if(entity == null) {
_logger.error("Entity is null for " + id + ". URL=" + url +
". Http code: " + code + " Error: " + status.getReasonPhrase());
mediaItem.setVisualIndexed(false);
_collector.emit(tuple(mediaItem, imageVector));
return;
}
InputStream input = entity.getContent();
byte[] imageContent = IOUtils.toByteArray(input);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageContent));
if(image != null) {
ImageVectorization imvec = new ImageVectorization(id, image, targetLengthMax, maxNumPixels);
if(mediaItem.getWidth()==null && mediaItem.getHeight()==null) {
mediaItem.setSize(image.getWidth(), image.getHeight());
}
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
if(vector==null || vector.length==0) {
_logger.error("Error in feature extraction for " + id);
}
imageVector = new ImageVector(id, url, vector);
}
_collector.emit(tuple(mediaItem, imageVector));
}
catch (Exception e) {
_logger.error(e);
_collector.emit(tuple(mediaItem, imageVector));
}
finally {
if(httpget != null)
httpget.abort();
}
}
开发者ID:socialsensor,
项目名称:storm-focused-crawler,
代码行数:75,
代码来源:FeatureExtractorBolt.java
示例14: execute
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public void execute(Tuple tuple) {
String id = tuple.getStringByField("id");
String url = tuple.getStringByField("url");
Double score = tuple.getDoubleByField("score");
boolean size = tuple.getBooleanByField("size");
System.out.println("Fetch and extract feature vector for " + id + " with score " + score);
try {
BufferedImage image = ImageIO.read(new URL(url));
Integer width=-1, height=-1;
boolean indexed = false;
if(image != null) {
ImageVectorization imvec = new ImageVectorization(id, image, targetLengthMax, maxNumPixels);
if(!size) {
width = image.getWidth();
height = image.getHeight();
}
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
indexed = visualIndex.index(id, vector);
}
if(indexed) {
_collector.emit(tuple(id, Boolean.TRUE, width, height));
}
else {
_collector.emit(tuple(id, Boolean.FALSE, width, height));
}
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
_collector.emit(tuple(id, Boolean.FALSE, -1, -1));
return;
}
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:47,
代码来源:VisualIndexer.java
示例15: run
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
@Override
public void run() {
while(true) {
DBObject query = new BasicDBObject();
query.put("indexed", false);
query.put("type", "image");
DBCursor items = input_collection.find(query);
if(items.size()==0)
break;
int k=0;
for(DBObject item : items) {
String id = (String) item.get("id");
String url = (String) item.get("url");
try {
InputStream is = new URL(url).openStream();
byte[] content = IOUtils.toByteArray(is);
if(++k%100==0) {
System.out.println(k + " media items indexed.");
break;
}
BufferedImage image = ImageIO.read(new ByteArrayInputStream(content));
ImageVectorization imvec = new ImageVectorization(id, image, targetLengthMax, maxNumPixels);
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
if(visualIndexHandler.index(id, vector)) {
DBObject q = new BasicDBObject("id", id);
DBObject o = new BasicDBObject("$set",
new BasicDBObject("indexed",true));
input_collection.update(q , o , false, true);
}
} catch (Exception e) {
continue;
}
}
}
System.out.println("DONE: All");
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:49,
代码来源:MediaItemsVisualIndexer.java
示例16: execute
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public void execute(Tuple tuple) {
String id = tuple.getStringByField("id");
String url = tuple.getStringByField("url");
//Double score = tuple.getDoubleByField("score");
boolean size = tuple.getBooleanByField("size");
//System.out.println("Fetch and extract feature vector for " + id + " with score " + score);
try {
byte[] imageContent = IOUtils.toByteArray(new URL(url));
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageContent));
Integer width=-1, height=-1;
boolean indexed = false;
if(image != null) {
ImageVectorization imvec = new ImageVectorization(id, image, targetLengthMax, maxNumPixels);
if(!size) {
width = image.getWidth();
height = image.getHeight();
}
ImageVectorizationResult imvr = imvec.call();
double[] vector = imvr.getImageVector();
indexed = visualIndex.index(id, vector);
}
if(indexed) {
_collector.emit(tuple(id, Boolean.TRUE, width, height));
}
else {
_collector.emit(tuple(id, Boolean.FALSE, width, height));
}
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage() + " url: "+url);
_collector.emit(tuple(id, Boolean.FALSE, -1, -1));
return;
}
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:49,
代码来源:VisualIndexerBolt.java
示例17: cluster
点赞 2
import gr.iti.mklab.visual.vectorization.ImageVectorization; //导入依赖的package包/类
public static void cluster() throws Exception {
String learningFiles = "/disk2_data/VisualIndex/learning_files/";
String[] codebookFiles = {
learningFiles + "surf_l2_128c_0.csv",
learningFiles + "surf_l2_128c_1.csv",
learningFiles + "surf_l2_128c_2.csv",
learningFiles + "surf_l2_128c_3.csv" };
String pcaFile = learningFiles + "pca_surf_4x128_32768to1024.txt";
int[] numCentroids = { 128, 128, 128, 128 };
int targetLengthMax = 1024;
int maxNumPixels = 768 * 512; // use 1024*768 for better/slower extraction
ImageVectorization.setFeatureExtractor(new SURFExtractor());
VladAggregatorMultipleVocabularies vladAggregator = new VladAggregatorMultipleVocabularies(codebookFiles, numCentroids,
AbstractFeatureExtractor.SURFLength);
ImageVectorization.setVladAggregator(vladAggregator);
int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
if(initialLength > targetLengthMax) {
PCA pca = new PCA(targetLengthMax, 1, initialLength, true);
pca.loadPCAFromFile(pcaFile);
ImageVectorization.setPcaProjector(pca);
}
String mongoHost = "160.40.51.18";
String mongoDb = "FeteBerlin";
String mongoCollection = "MediaItems";
MongoClient client = new MongoClient(mongoHost);
DB db = client.getDB(mongoDb);
DBCollection coll = db.getCollection(mongoCollection);
DBCollection clustersCollection = db.getCollection("MediaItemClusters3");
VisualIndexHandler vIndex = new VisualIndexHandler("http://160.40.51.18:8080/VisualIndexService", "fete3");
DBCursor cursor = coll.find(new BasicDBObject("type","image"));
ArrayBlockingQueue<Vec> queue1 = new ArrayBlockingQueue<Vec>(5000);
ArrayBlockingQueue<Vec> queue2 = new ArrayBlockingQueue<Vec>(5000);
Thread clusterer = new Thread(new Clusterer(queue2, vIndex, coll, clustersCollection));
List<Thread> extractors = new ArrayList<Thread>();
for(int i=0;i<48;i++) {
extractors.add(new Thread(new Extractor(queue1, queue2)));
}
clusterer.start();
for(Thread t : extractors) {
t.start();
}
while(cursor.hasNext()) {
DBObject mItem = cursor.next();
String id = (String) mItem.get("id");
String url = (String) mItem.get("url");
try {
Vec vec = new Vec(id, url, null);
queue1.put(vec);
Thread.sleep(5);
}
catch(Exception e) {
e.printStackTrace();
}
}
System.out.println("Wait for clusterer to finish!!!");
clusterer.join();
}
开发者ID:socialsensor,
项目名称:socialsensor-multimedia-analysis,
代码行数:77,
代码来源:VisualIndexerBolt.java