-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new background search button. Fix whitespace issues. Move default prefix code back to HT prefix.
- Loading branch information
1 parent
aabe437
commit a4a2a31
Showing
11 changed files
with
264 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"preset": "crockford", | ||
"disallowDanglingUnderscores": null, | ||
"validateQuoteMarks": null, | ||
"requireMultipleVarDecl": true, | ||
"requireCamelCaseOrUpperCaseIdentifiers": null | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
############################################################################### | ||
# Copyright Kitware Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 ( the "License" ); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
############################################################################### | ||
|
||
from girder.api import access | ||
from girder.api.describe import Description | ||
from girder.api.rest import Resource | ||
from girder import logger | ||
|
||
import requests | ||
import os | ||
|
||
|
||
class ImageBackgroundSearch(Resource): | ||
def __init__(self): | ||
self.resourceName = 'imagebackgroundsearch' | ||
self.route('GET', (), self.getImageSearch) | ||
|
||
@access.public | ||
def getImageSearch(self, params): | ||
return self._imageSearch(params) | ||
|
||
@access.public | ||
def postImageSearch(self, params): | ||
return self._imageSearch(params) | ||
|
||
def _imageSearch(self, params): | ||
print params | ||
return [{'id': d[0], 'score': d[1]} for d in requests.post( | ||
os.environ['IMAGE_SPACE_CMU_BACKGROUND_SEARCH'], | ||
data=params['url'], | ||
headers={ | ||
'Content-type': 'text', | ||
'Content-length': str(len(params['url'])) | ||
}, | ||
verify=False) | ||
.json()] | ||
getImageSearch.description = Description('Searches images by background') |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
imagespace.views.DisplayView = imagespace.View.extend({ | ||
events: { | ||
'click .im-add-user-data': function (event) { | ||
var id = $(event.currentTarget).attr('im-id'), | ||
image = this.imageIdMap[id]; | ||
imagespace.userDataView.addUserImage(image); | ||
}, | ||
|
||
'click .im-details': function (event) { | ||
var id = $(event.currentTarget).attr('im-id'), | ||
image = this.imageIdMap[id]; | ||
this.imageDetailWidget = new imagespace.views.ImageDetailWidget({ | ||
el: $('#g-dialog-container'), | ||
image: image, | ||
parentView: this | ||
}); | ||
this.imageDetailWidget.render(); | ||
}, | ||
|
||
'click .im-find-similar': function (event) { | ||
var id = $(event.currentTarget).attr('im-id'), | ||
image = this.imageIdMap[id]; | ||
$('.alert-info').html('Finding similar images <i class="icon-spin5 animate-spin"></i>').removeClass('hidden'); | ||
this.$('.btn-lg').addClass('disabled'); | ||
$(event.currentTarget).parent().find('.im-find-similar') | ||
.html('<i class="icon-spin5 animate-spin"></i>'); | ||
if (image.histogram) { | ||
this.findSimilarImages(image); | ||
} else { | ||
girder.restRequest({ | ||
path: 'imagefeatures', | ||
data: { | ||
url: image.imageUrl | ||
}, | ||
method: 'POST' | ||
}).done(_.bind(function (features) { | ||
image.histogram = features.histogram; | ||
this.findSimilarImages(image); | ||
}, this)); | ||
} | ||
}, | ||
|
||
'mouseover .im-image-area': function (event) { | ||
$(event.currentTarget).find('.im-caption-content').removeClass('hidden'); | ||
}, | ||
|
||
'mouseout .im-image-area': function (event) { | ||
$(event.currentTarget).find('.im-caption-content').addClass('hidden'); | ||
} | ||
}, | ||
|
||
initialize: function (settings) { | ||
girder.cancelRestRequests('fetch'); | ||
this.resLimit = 30; | ||
this.imagePathRoot = '/data/roxyimages/'; | ||
// this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/' | ||
this.results = settings.results; | ||
this.imageIdMap = {}; | ||
this.results.forEach(_.bind(function (result) { | ||
result.imageUrl = result.id; | ||
this.imageIdMap[result.id] = result; | ||
}, this)); | ||
|
||
this.render(); | ||
}, | ||
|
||
render: function () { | ||
this.$el.html(imagespace.templates.search({ | ||
results: this.results, | ||
showText: true | ||
})); | ||
return this; | ||
}, | ||
|
||
findSimilarImages: function (image) { | ||
girder.restRequest({ | ||
path: 'imagesearch', | ||
data: { | ||
url: image.imageUrl, | ||
histogram: JSON.stringify(image.histogram || []), | ||
limit: this.resLimit | ||
} | ||
}).done(_.bind(function (results) { | ||
var query = '(', count = 0; | ||
results.forEach(_.bind(function (result, index) { | ||
var parts = result.id.split('/'), | ||
file = parts[parts.length - 1]; | ||
if (file.length < 30) { | ||
return; | ||
} | ||
if (result.id.indexOf('cmuImages') !== -1) { | ||
file = 'cmuImages/' + file; | ||
} | ||
file = this.imagePathRoot + file; | ||
if (count < this.resLimit) { | ||
query += 'id:"' + file + '" '; | ||
count += 1; | ||
} | ||
}, this)); | ||
query += ')'; | ||
imagespace.router.navigate('search/' + encodeURIComponent(query), {trigger: true}); | ||
|
||
$('.btn-lg').removeClass('disabled'); | ||
$('.im-find-similar').html('<i class="icon-search"></i>'); | ||
|
||
$('.alert-info').addClass('hidden'); | ||
$('.alert-success').text('Search complete.').removeClass('hidden'); | ||
setTimeout(function () { | ||
$('.alert-success').addClass('hidden') | ||
}, 5000); | ||
|
||
}, this)); | ||
} | ||
|
||
}); | ||
|
||
imagespace.router.route('display/:content', 'display', function (content) { | ||
$('.im-search').val(content); | ||
girder.events.trigger('g:navigateTo', imagespace.views.DisplayView, { | ||
results: JSON.parse(content) | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.