Skip to content

Commit

Permalink
move printSupportedLangs together with other print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
srirangav committed Apr 25, 2022
1 parent accf1b0 commit 7c440af
Showing 1 changed file with 138 additions and 138 deletions.
276 changes: 138 additions & 138 deletions vocr.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,144 @@ static void printInfo(const char *format, ...)
va_end(args);
}

#ifdef VOCR_DEBUG

/*
printSupportedLangs - list what languages are supported by
VNRecognizeTextRequest
see: https://developer.apple.com/documentation/vision/vnrecognizetextrequest/3152642-recognitionlanguages?language=objc
*/

static void printSupportedLangs(void)
{
NSArray<NSString *> *langs;
NSUInteger i = 0, numLangs = 0;

/* fast, v1 */

langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelFast
revision:
VNRecognizeTextRequestRevision1
error: nil];
if (langs != nil)
{
fprintf(stderr,"Fast, v1: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}

/* fast, v2 */

if (@available(macos 11, *))
{
langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelFast
revision:
VNRecognizeTextRequestRevision2
error: nil];
if (langs != nil)
{
fprintf(stderr,"Fast, v2: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}
}

/* accurate, v1 */

langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelAccurate
revision:
VNRecognizeTextRequestRevision1
error: nil];
if (langs != nil)
{
fprintf(stderr,"Accurate, v1: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}

/* accurate, v2 */

if (@available(macos 11, *))
{
langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelAccurate
revision:
VNRecognizeTextRequestRevision2
error: nil];
if (langs != nil)
{
fprintf(stderr,"Accurate, v2: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}
}
}
#endif /* VOCR_DEBUG */

/* ocrImage - try to ocr the specified image */

static BOOL ocrImage(CGImageRef cgImage,
Expand Down Expand Up @@ -713,144 +851,6 @@ static BOOL ocrFile(const char *file,
return NO;
}

#ifdef VOCR_DEBUG

/*
printSupportedLangs - list what languages are supported by
VNRecognizeTextRequest
see: https://developer.apple.com/documentation/vision/vnrecognizetextrequest/3152642-recognitionlanguages?language=objc
*/

static void printSupportedLangs(void)
{
NSArray<NSString *> *langs;
NSUInteger i = 0, numLangs = 0;

/* fast, v1 */

langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelFast
revision:
VNRecognizeTextRequestRevision1
error: nil];
if (langs != nil)
{
fprintf(stderr,"Fast, v1: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}

/* fast, v2 */

if (@available(macos 11, *))
{
langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelFast
revision:
VNRecognizeTextRequestRevision2
error: nil];
if (langs != nil)
{
fprintf(stderr,"Fast, v2: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}
}

/* accurate, v1 */

langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelAccurate
revision:
VNRecognizeTextRequestRevision1
error: nil];
if (langs != nil)
{
fprintf(stderr,"Accurate, v1: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}

/* accurate, v2 */

if (@available(macos 11, *))
{
langs = [VNRecognizeTextRequest
supportedRecognitionLanguagesForTextRecognitionLevel:
VNRequestTextRecognitionLevelAccurate
revision:
VNRecognizeTextRequestRevision2
error: nil];
if (langs != nil)
{
fprintf(stderr,"Accurate, v2: ");
numLangs = [langs count];
if (numLangs > 0)
{
for (i = 0; i < numLangs; i++)
{
fprintf(stderr,
"'%s' ",
[[langs objectAtIndex: i]
cStringUsingEncoding: NSUTF8StringEncoding]);
}
}
else
{
fprintf(stderr,"None");
}
fprintf(stderr, "\n");
}
}
}
#endif /* VOCR_DEBUG */

/* main */

int main(int argc, char * const argv[])
Expand Down

0 comments on commit 7c440af

Please sign in to comment.