Changeset 37105 for gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js
- Timestamp:
- 2023-01-05T23:53:30+13:00 (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js
r37075 r37105 218 218 219 219 220 /*221 222 https://stackoverflow.com/questions/57071788/google-vision-api-text-detection-display-words-by-block223 224 225 https://gist.github.com/UBISOFT-1/f00e4d22790f4af378d70b237fa56ca9226 227 response = client.text_detection(image=image)228 # The actual response for the first page of the input file.229 breaks = vision.enums.TextAnnotation.DetectedBreak.BreakType230 paragraphs = []231 lines = []232 # extract text by block of detection233 for page in response.full_text_annotation.pages:234 for block in page.blocks:235 for paragraph in block.paragraphs:236 para = ""237 line = ""238 suppose = str(paragraph.bounding_box)239 suppose = suppose.replace('vertices ','')240 print(suppose)241 for word in paragraph.words:242 for symbol in word.symbols:243 line += symbol.text244 if symbol.property.detected_break.type == breaks.SPACE:245 line += ' '246 if symbol.property.detected_break.type == breaks.EOL_SURE_SPACE:247 line += ' '248 lines.append(line)249 para += line250 line = ''251 if symbol.property.detected_break.type == breaks.LINE_BREAK:252 lines.append(line)253 para += line254 line = ''255 paragraphs.append(para)256 257 258 return "\n".join(paragraphs)259 260 261 262 263 https://blog.searce.com/tips-tricks-for-using-google-vision-api-for-text-detection-2d6d1e0c6361264 265 def draw_boxes(image, bounds, color,width=5):266 draw = ImageDraw.Draw(image)267 for bound in bounds:268 draw.line([269 bound.vertices[0].x, bound.vertices[0].y,270 bound.vertices[1].x, bound.vertices[1].y,271 bound.vertices[2].x, bound.vertices[2].y,272 bound.vertices[3].x, bound.vertices[3].y,273 bound.vertices[0].x, bound.vertices[0].y],fill=color, width=width)274 return image275 def get_document_bounds(response, feature):276 for i,page in enumerate(document.pages):277 for block in page.blocks:278 if feature==FeatureType.BLOCK:279 bounds.append(block.bounding_box)280 for paragraph in block.paragraphs:281 if feature==FeatureType.PARA:282 bounds.append(paragraph.bounding_box)283 for word in paragraph.words:284 for symbol in word.symbols:285 if (feature == FeatureType.SYMBOL):286 bounds.append(symbol.bounding_box)287 if (feature == FeatureType.WORD):288 bounds.append(word.bounding_box)289 return bounds290 bounds=get_document_bounds(response, FeatureType.WORD)291 draw_boxes(image,bounds, 'yellow')292 293 */294 295 220 296 221 … … 301 226 302 227 var canvas_index = goto_page -1; 228 229 var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + gs.cgiParams.d; 230 var httpDocumentIIIFManifest = httpDocument + "?sa=iiif-manifest&ed=1&excerptid-text=iiif-manifest"; 231 232 //const endpointUrl = 'https://intermuse.sowemustthink.space/simpleAnnotationStore/annotation'; 233 //const endpointUrl = '/simpleAnnotationStore/annotation'; 303 234 304 235 var mirador3_config = { 305 236 "manifests": { 306 "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {237 httpDocumentIIIFManifest: { 307 238 "provider": "InterMusE" 308 239 } 309 240 }, 310 "window" : { "panels": { "annotations": true, "attribution": true }, 311 "defaultSideBarPanel": "annotations", 312 "sideBarOpenByDefault": true 313 }, 241 "window" : { "panels": { "attribution": true, "search": true } }, 314 242 315 243 //"annotations": { … … 317 245 // "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'], 318 246 //}, 247 /* 319 248 "requests": { 320 249 "postprocessors": [ … … 330 259 } 331 260 ] 332 }, 261 },*/ 333 262 334 263 "windows": [ 335 264 { 336 "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",265 "loadedManifest": httpDocumentIIIFManifest, 337 266 "canvasIndex": canvas_index, 338 267 "thumbnailNavigationPosition": 'far-bottom' … … 341 270 }; 342 271 272 var includeFileAssocOpenAnnotations = gs.variables.optionIncludeFileAssocOpenAnnotations; 273 var includeEditableOpenAnnotations = gs.variables.optionIncludeEditableOpenAnnotations; 274 275 console.log("**** includeFileAssocOpenAnnotations = " + includeFileAssocOpenAnnotations); 276 console.log("**** includeEditableOpenAnnotations = " + includeEditableOpenAnnotations); 277 278 if ((includeFileAssocOpenAnnotations == 'true') || (includeEditableOpenAnnotations == 'true')) { 279 // Activate the annotations plugin 280 281 mirador3_config.window.panels.annotations = true; 282 283 mirador3_config.window.defaultSideBarPanel = "annotations"; 284 mirador3_config.window.sideBarOpenByDefault = true; 285 286 if (includeEditableOpenAnnotations == 'true') { 287 288 //console.log("**** gs.variables.endpointURL = '" + gs.variables.endpointURL + "'"); 289 //const endpointURL = gs.variables.endpointURL; 290 291 var endpointURL = gs.variables.optionIncludeEditableOpenAnnotationsEndpointURL; 292 console.log("**** endpointURL = '" + endpointURL + "'"); 293 294 mirador3_config.annotation = {}; 295 296 if ((endpointURL == "") || (endpointURL == "localStorage")) { 297 mirador3_config.annotation.adapter = (canvasId) => new mirador3WithAnnotations.LocalStorageAdapter(`localStorage://?canvasId=${canvasId}`) 298 } 299 else { 300 mirador3_config.annotation.adapter = (canvasId) => new mirador3WithAnnotations.SimpleAnnotationServerV2Adapter(canvasId, endpointURL); 301 } 302 303 // **** add in a further options for this ???? 304 305 mirador3_config.annotation.exportLocalStorageAnnotations = true; // display annotation JSON export button 306 307 } 308 } 343 309 344 310 var mirador3_viewer = mirador3WithAnnotations.initMirador3Viewer('mirador3-viewer',mirador3_config); 345 346 /*347 var mirador3_viewer = Mirador.viewer({348 "id": "mirador3-viewer",349 "manifests": {350 "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {351 "provider": "IntermusE"352 }353 },354 "window" : { "panels" : { "annotations": true, "attribution": false } },355 //"annotations": {356 // "htmlSanitizationRuleSet": 'iiif', // See src/lib/htmlRules.js for acceptable values357 // "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],358 //},359 "requests": {360 "postprocessors": [361 (url, action) => {362 if (action.type === "mirador/RECEIVE_MANIFEST") {363 //console.log(action)364 //console.log(iiif_manifest);365 return {366 ...action ,367 "manifestJson": iiif_manifest368 };369 }370 }371 ]372 },373 374 "windows": [375 {376 "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",377 "canvasIndex": 0,378 "thumbnailNavigationPosition": 'far-bottom'379 }380 ]381 });382 */383 311 384 312 return mirador3_viewer;
Note:
See TracChangeset
for help on using the changeset viewer.