Disable hand written text detection - google-cloud-platform

I am using Google.Cloud.Vision.V1 for OCR.
I need to disable the hand written text detection in method when I call the "DetectDocumentText" method in "ImageAnnotatorClient" class.
I only want to perform the OCR not ICR.
This is the code snippet I am using:
FileInfo fi = new FileInfo(imageFile);
var image = Image.FromFile(fi.FullName);
var client = ImageAnnotatorClient.Create();
var response = client.DetectDocumentText(image);

Related

Use MFC CRichEditCtrl to display QR code with proper size

I am trying to display a QR code in a MFC CRichEditCtrl, but the resulting size is way too small.
This is the code I'm using to put the QR into the edit control:
SETTEXTEX TextInfo = {0};
TextInfo.flags = ST_SELECTION;
TextInfo.codepage = CP_UTF8;
LRESULT res = ::SendMessage(m_editQR.m_hWnd, EM_SETTEXTEX, (WPARAM)&TextInfo, (LPARAM)buffer);
The "buffer" parameter is a char array; its content is read from a UTF-8 file containing the QR code string. This file shows this way in Notepad++:
The QR code also shows correctly if I print the same buffer in a console app I made for tests.
However, the QR code is shown in my MFC testing app like this:
It looks like a problem with the size of the font used to render the QR (I'm using the default for the Rich Edit control). So I tried to change the font and its size.
This is the code I'm using to set up the char format:
CHARFORMAT selCharformat;
m_editQR.GetSelectionCharFormat(selCharformat);
selCharformat.cbSize = sizeof(CHARFORMAT);
selCharformat.dwMask = CFM_FACE | CFM_SIZE | CFM_CHARSET;
selCharformat.yHeight = 20*8;
selCharformat.bCharSet = DEFAULT_CHARSET;
selCharformat.bPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
lstrcpy(selCharformat.szFaceName, _T("Console"));
BOOL bRes = m_editQR.SetSelectionCharFormat(selCharformat);
But then the QR is messed up, like this:
I guess there is a problem with the setup of my Rich Edit ctrl, but can't find the correct settings (I'm not very experienced with MFC).
Can you guys help?

How to export .drawing file

I'm trying to draw something in app with PencilKit. Now I want to export my drawings from my file, so I could open send it to other devices, and then open it(in format PKDrawing).
var canvasView = PKCanvasView()
//user does drawing...
let data = canvasView.drawing.dataRepresentation()
data will be of type Data. You can then write that to a file (https://developer.apple.com/documentation/foundation/nsdata/1414800-write) and export it however you want.
For example, you could use ExportFilesAction: https://www.youtube.com/watch?v=iDseNgvdTpA
To load this data back into a PKDrawing, you can:
let drawing = try? PKDrawing(data: dataToLoad)

reading barcode using Aspose

I have a PDF file that includes a page with the Barcode. The barcode was originally created using DecodeType.Code128
I am using ASPOSE.PDF and Aspose.Barcode to find the barcode and the page number.
var barcodePageNumbers = new List<int>();
var currentPageNumber = 0;
using (PdfConverter converter = new PdfConverter())
{
converter.BindPdf(sourcefilePath);
converter.RenderingOptions.BarcodeOptimization = true;
converter.DoConvert();
while (converter.HasNextImage())
{
currentPageNumber++;
using (var ms = new MemoryStream())
{
converter.GetNextImage(ms);
ms.Seek(0L, SeekOrigin.Begin);
BarCodeReader reader = new BarCodeReader(ms, DecodeType.Code128);
while (reader.Read())
{
var text = reader.GetCodeText();
if (text == _barcodeTextToMatch)
{
barcodePageNumbers.Add(currentPageNumber);
}
}
}
}
}
Every now and then we get bad quality barcode pdf like the one attached herewith. (Note the attached PDF has 3 pages. I have created page 1 and 3 using tool. and the 2nd page which has barcode is from the original PDF.)
The code above works as long as the barcode quality is good. but if the quality is bad then it not able able to recognize its barcode.
Sample File
What other optimization technique can be used here?
At first, what the version of Aspose.PDF and Aspose.Barcode do you use? Because I tried the pdf file on the last Aspose.Barcode(develop version) it is recognized well.
string lFileName = #"d:\save\rec\merged.pdf";
var currentPageNumber = 0;
var barcodePageNumbers = new List<int>();
using (Aspose.Pdf.Facades.PdfConverter converter = new Aspose.Pdf.Facades.PdfConverter())
{
converter.BindPdf(lFileName);
converter.RenderingOptions.BarcodeOptimization = true;
converter.DoConvert();
while (converter.HasNextImage())
{
currentPageNumber++;
using (var ms = new MemoryStream())
{
converter.GetNextImage(ms);
ms.Seek(0L, SeekOrigin.Begin);
BarCodeReader reader = new BarCodeReader(ms, DecodeType.Code128);
while (reader.Read())
{
var text = reader.GetCodeText();
barcodePageNumbers.Add(currentPageNumber);
}
}
}
}
MessageBox.Show(string.Join(";", barcodePageNumbers.ToArray()));
Here are extracted images from pdf file:
page_2.tiff - full image
page2_cut.png - cut image.
Both are recognized well.
Image distortion, which you can see on the image, is salt and paper issue. We solve this problem in most cases in the recognition module, but current detection module of barcode position could mark barcodes with so strong salt and paper distortion as nonbarcode area. At this time we don’t have optimization for this, but we are developing SVM(support vector machines) detector which detects barcode areas better and also will have options to optimize recognition with these issues. SVM barcode areas detector will be added to Aspose.Barcode in 2020Q1.
Current workaround for this: if you know possible barcode area you can set barcode recognition region with SetBarCodeImage(Bitmap value, Rectangle area) and this helps current Gradient detector to detect so noisy areas.

Sitecore How to get the value inside the field 'Media' of a Media Item

Update 2:
I am still fighting to get the Icon save on the server.
Here what I am doing:
Item item = Sitecore.Context.Database.GetItem(imageId);
var imageIconUrl = Sitecore.Resources.Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id32x32);
if (!string.IsNullOrEmpty(imageIconUrl))
{
// download the icon from the url
var iconFullPath = "e:\\pngIcons\\excelIcon.png";
var webClient = new System.Net.WebClient();
var downloadPath = "http://serverName/" + imageIconUrl;
webClient.DownloadFile(downloadPath, iconFullPath);
}
The variable downloadPath contains following string:
http://serverName/sitecore/shell/themes/standard/~/media/E503BA48C89B422D8400393F1C7086A7.ashx?h=32&thn=1&w=32&db=master
At the end what I can see is a png file but there is nothing in it. I also copy the string I get in variable downloadPath and pasted it in browser and I can see the Icon as follow:
Please let me know what I am doing wrong. Or How I can save the Icon. Thanks!!
Original Question:
The sitecore media item has a field "Media". I am talking about this:
I want to access this field. And the reason is:
If I access it with e.g. item.GetMediaStream() then I will get the complete file. I just want to save this little icon some how on the server. Is it possible ?
To get the icon/thumbnail you can use
var icon = Sitecore.Resources.Media.MediaManager.GetThumbnailUrl(mediaItem);
To get the url of the thumbnail.
If you want the stream of the thumbnail you need to use the MediaData object. Like this:
var mediaItem = new MediaItem(item)
var mediaData = new MediaData(mediaItem);
var iconStream = mediaData.GetThumbnailStream();
if (iconStream.Length < 0)
{
// The stream is empty, its probably a file that Sitecore can't
// generate a thumbnail for. Just use the Icon
var icon = item.Appearance.Icon;
}
This will get the icon or thumbnail of the actual media blob that is attached to the media item. If you just want the icon of the Sitecore item, then use Martins method.
If the stream is empty, then Sitecore can't generate a thumbnail for it, so you can just use the icon file for the media item template. item.Appearance.Icon
Appearance section (of Standard Template) has a field called Icon - this is where you can modify icon for the item. There is also a field called Thumbnail - your excel icon is sitting there
You can access the field programmatically, just mind that it starts with two underscores: __Icon:
var iconField = item.Fields["__Icon"];
var thumbnailField = item.Fields["__Thumbnail"];
Update: As you asked, below is the code that saves either of fields into the file on a drive. I have tested the code and confirm successfully stores icon from thumbnail field into the file:
string mediaItemPath = "/sitecore/media library/Files/ExcelFile";
string mediaFiedlName = "Thumbnail"; // also can be "__Icon"
var item = Sitecore.Context.Database.GetItem(mediaItemPath);
var iconField = item.Fields[mediaFiedlName];
if (iconField.HasBlobStream)
{
var thumb = (ImageField)iconField;
var bl = ((MediaItem)thumb.MediaItem).InnerItem.Fields["blob"];
Stream stream = bl.GetBlobStream();
byte[] buffer = new byte[8192];
using (FileStream fs = File.Create("D:\\you_file_name.ico")) // change your path
{
int length;
do
{
length = stream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, length);
}
while (length > 0);
fs.Flush();
fs.Close();
}
}
Update 2: If that does not help then I would advise to look around the way how that icon gets generated on Media field in Sitecore. In the worst case you may do the following - right click that icon and see its url. You will have something similar to what I assign to variable below:
string url = "http://test81/sitecore/shell/Applications/-/media/B4F61650CBE84EE396649602C0C48E1B.ashx?bc=White&db=master&h=128&la=en&mw=640&thn=1&vs=1&ts=b8046903-ae57-4f9d-9dd5-b626ee5eee90";
Of course your URL should have your hostname and media prefix and the rest of parameters. Then use Webclient with that modified URL:
WebClient webClient = new WebClient();
webClient.DownloadFile(url, "e:\\you_file_name.ico");
Not ideal, but may work. Note, that the code above should work in a context of already logged user, so you need to authorise you Webclient prior that (many articles on S.O. how to do that).
Please reply if that approach has worked for you (I've spent decent time writing and testing that code in debugger, so would want to know whether that helped)

Set focus to a column filter in an Infragistics WebDataGrid

I am using an Infragistics NetAdvantage WebDataGrid with filtering set.
On page load, I would like to open the first filter’s textbox, and set the focus there, so that it is ready for the user to start typing the text with which to filter.
I have seen an example online of how to do this for the jQuery grid, but not for the WebDataGrid
I want something along the lines of:
myWebDataGrid.Behaviors.Filtering.ColumnFilters[2].RuleTextNode.focus;
I am using Infragistics35.Web.v11.2, Version=11.2.20112.2025
To do this you can call enterEditMode on the filter row when your page loads, passing in the specific cell you want edit:
function enterEditFilter() {
var grid = $find('<%= grid.ClientID %>');
var filtering = grid.get_behaviors().get_filtering();
var filterRow = filtering._row;
var cell = filterRow.get_cellByColumnKey('Text');
filtering.enterEditMode(cell);
}
Please note that to do this you have to be able to get access to the filter row. It doesn't appear that there is a way to access this through the public API so I use the private variable _row. This is not a recommended approach as that variable may change, so I suggest that you submit a new product idea to have the filter row added to the public API. You can do this on the following page:
http://ideas.infragistics.com/
Another thing to note is that the default filter type is "All" so you'll also want to change this. You can do this by handling the client side filtering event and setting the rule there:
function grid_filtering(sender, eventArgs) {
var filters = eventArgs.get_columnFilters();
for (var i = 0; i < filters.length; i++) {
var condition = filters[i].get_condition();
if (condition.get_rule() === 0) {
var columnType = filters[i].get_columnType();
if (columnType == 'string') {
condition.set_rule($IG.TextFilterRules.Equals);
}
else if (columnType == 'number') {
condition.set_rule($IG.NumericFilterRules.Equals);
}
}
}
}