jabcode
 All Classes Files Functions Variables Enumerations Macros
detector.c File Reference

JABCode detector. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "jabcode.h"
#include "detector.h"
#include "decoder.h"
#include "encoder.h"

Functions

jab_boolean checkPatternCross (jab_int32 *state_count, jab_float *module_size)
 Check the proportion of layer sizes in finder pattern. More...
 
jab_boolean checkModuleSize (jab_float size_r, jab_float size_g, jab_float size_b)
 Check if the input module sizes are the same. More...
 
jab_boolean seekPattern (jab_bitmap *ch, jab_int32 row, jab_int32 col, jab_int32 *start, jab_int32 *end, jab_float *center, jab_float *module_size, jab_int32 *skip)
 Find a candidate scanline of finder pattern. More...
 
jab_boolean seekPatternHorizontal (jab_byte *row, jab_int32 *startx, jab_int32 *endx, jab_float *centerx, jab_float *module_size, jab_int32 *skip)
 Find a candidate horizontal scanline of finder pattern. More...
 
jab_int32 crossCheckPatternDiagonal (jab_bitmap *image, jab_int32 type, jab_float module_size_max, jab_float *centerx, jab_float *centery, jab_float *module_size, jab_int32 *dir, jab_boolean both_dir)
 Crosscheck the finder pattern candidate in diagonal direction. More...
 
jab_boolean crossCheckPatternVertical (jab_bitmap *image, jab_int32 module_size_max, jab_float centerx, jab_float *centery, jab_float *module_size)
 Crosscheck the finder pattern candidate in vertical direction. More...
 
jab_boolean crossCheckPatternHorizontal (jab_bitmap *image, jab_float module_size_max, jab_float *centerx, jab_float centery, jab_float *module_size)
 Crosscheck the finder pattern candidate in horizontal direction. More...
 
jab_boolean crossCheckPatternCh (jab_bitmap *ch, jab_int32 type, jab_int32 h_v, jab_float module_size_max, jab_float *module_size, jab_float *centerx, jab_float *centery, jab_int32 *dir, jab_int32 *dcc)
 Crosscheck the finder pattern candidate in one channel. More...
 
jab_boolean crossCheckPattern (jab_bitmap *ch[], jab_finder_pattern *fp, jab_int32 h_v)
 Crosscheck the finder pattern candidate. More...
 
jab_int32 saveAlignmentPattern (jab_alignment_pattern *ap, jab_alignment_pattern *aps, jab_int32 *counter)
 Save a found alignment pattern into the alignment pattern list. More...
 
void saveFinderPattern (jab_finder_pattern *fp, jab_finder_pattern *fps, jab_int32 *counter, jab_int32 *fp_type_count)
 Save a found finder pattern into the finder pattern list. More...
 
void drawFoundFinderPatterns (jab_finder_pattern *fps, jab_int32 number, jab_int32 color)
 
void removeBadPatterns (jab_finder_pattern *fps, jab_int32 fp_count, jab_float mean, jab_float threshold)
 Remove the finder patterns with greatly different module size. More...
 
jab_finder_pattern getBestPattern (jab_finder_pattern *fps, jab_int32 fp_count)
 Find the finder pattern with most detected times. More...
 
jab_int32 selectBestPatterns (jab_finder_pattern *fps, jab_int32 fp_count, jab_int32 *fp_type_count)
 Select the best finder patterns out of the list. More...
 
void scanPatternVertical (jab_bitmap *ch[], jab_int32 min_module_size, jab_finder_pattern *fps, jab_int32 *fp_type_count, jab_int32 *total_finder_patterns)
 Scan the image vertically. More...
 
jab_finder_patternfindMasterSymbol (jab_bitmap *ch[], jab_detect_mode mode)
 Find the master symbol in the image. More...
 
jab_float crossCheckPatternDiagonalAP (jab_bitmap *image, jab_int32 ap_type, jab_int32 module_size_max, jab_point center, jab_int32 *dir)
 Crosscheck the alignment pattern candidate in diagonal direction. More...
 
jab_float crossCheckPatternVerticalAP (jab_bitmap *image, jab_point center, jab_int32 module_size_max, jab_float *module_size)
 Crosscheck the alignment pattern candidate in vertical direction. More...
 
jab_float crossCheckPatternHorizontalAP (jab_byte *row, jab_int32 channel, jab_int32 startx, jab_int32 endx, jab_int32 centerx, jab_int32 ap_type, jab_float module_size_max, jab_float *module_size)
 Crosscheck the alignment pattern candidate in horizontal direction. More...
 
jab_boolean crossCheckPatternAP (jab_bitmap *ch[], jab_int32 y, jab_int32 minx, jab_int32 maxx, jab_int32 cur_x, jab_int32 ap_type, jab_float max_module_size, jab_float *centerx, jab_float *centery, jab_float *module_size, jab_int32 *dir)
 Crosscheck the alignment pattern. More...
 
jab_alignment_pattern findAlignmentPattern (jab_bitmap *ch[], jab_float x, jab_float y, jab_float module_size, jab_int32 ap_type)
 Find alignment pattern around a given position. More...
 
jab_boolean findSlaveSymbol (jab_bitmap *bitmap, jab_bitmap *ch[], jab_decoded_symbol *host_symbol, jab_decoded_symbol *slave_symbol, jab_int32 docked_position)
 Find a docked slave symbol. More...
 
jab_int32 getSideSize (jab_int32 size, jab_int32 *flag)
 Get the nearest valid side size to a given size. More...
 
jab_vector2d calculateSideSize (jab_bitmap *ch[], jab_finder_pattern *fps, jab_float *module_size)
 Calculate the side sizes of master symbol. More...
 
jab_bitmapsampleSymbolByAlignmentPattern (jab_bitmap *bitmap, jab_bitmap *ch[], jab_decoded_symbol *symbol, jab_alignment_pattern *fps)
 Sample a symbol with help of alignment patterns. More...
 
jab_boolean detectMaster (jab_bitmap *bitmap, jab_bitmap *ch[], jab_decoded_symbol *master_symbol)
 Detect and decode a master symbol. More...
 
jab_bitmapdetectSlave (jab_bitmap *bitmap, jab_bitmap *ch[], jab_decoded_symbol *host_symbol, jab_decoded_symbol *slave_symbol, jab_int32 docked_position)
 Detect a slave symbol. More...
 
jab_boolean decodeDockedSlaves (jab_bitmap *bitmap, jab_bitmap *ch[], jab_decoded_symbol *symbols, jab_int32 host_index, jab_int32 *total)
 Decode docked slave symbols around a host symbol. More...
 
void preprocessImage (jab_bitmap *bitmap)
 Preprocess the image. More...
 
jab_datadecodeJABCodeEx (jab_bitmap *bitmap, jab_int32 mode, jab_int32 *status, jab_decoded_symbol *symbols, jab_int32 max_symbol_number)
 Extended function to decode a JAB Code. More...
 
jab_datadecodeJABCode (jab_bitmap *bitmap, jab_int32 mode, jab_int32 *status)
 Decode a JAB Code. More...
 

Detailed Description

JABCode detector.

libjabcode - JABCode Encoding/Decoding Library

Copyright 2016 by Fraunhofer SIT. All rights reserved. See LICENSE file for full terms of use and distribution.

Contact: Huajian Liu liu@s.nosp@m.it.f.nosp@m.raunh.nosp@m.ofer.nosp@m..de Waldemar Berchtold walde.nosp@m.mar..nosp@m.berch.nosp@m.told.nosp@m.@sit..nosp@m.frau.nosp@m.nhofe.nosp@m.r.de

Function Documentation

jab_vector2d calculateSideSize ( jab_bitmap ch[],
jab_finder_pattern fps,
jab_float *  module_size 
)

Calculate the side sizes of master symbol.

Parameters
chthe binarized color channels of the image
fpsthe finder patterns
module_sizethe module size
Returns
the horizontal and vertical side sizes
jab_boolean checkModuleSize ( jab_float  size_r,
jab_float  size_g,
jab_float  size_b 
)

Check if the input module sizes are the same.

Parameters
size_rthe first module size
size_gthe second module size
size_bthe third module size
Returns
JAB_SUCCESS | JAB_FAILURE
jab_boolean checkPatternCross ( jab_int32 *  state_count,
jab_float *  module_size 
)

Check the proportion of layer sizes in finder pattern.

Parameters
state_countthe layer sizes in pixel
module_sizethe module size
Returns
JAB_SUCCESS | JAB_FAILURE
jab_boolean crossCheckPattern ( jab_bitmap ch[],
jab_finder_pattern fp,
jab_int32  h_v 
)

Crosscheck the finder pattern candidate.

Parameters
chthe binarized color channels of the image
fpthe finder pattern
h_vthe direction of the candidate scanline, 0:horizontal 1:vertical
Returns
JAB_SUCCESS | JAB_FAILURE
jab_boolean crossCheckPatternAP ( jab_bitmap ch[],
jab_int32  y,
jab_int32  minx,
jab_int32  maxx,
jab_int32  cur_x,
jab_int32  ap_type,
jab_float  max_module_size,
jab_float *  centerx,
jab_float *  centery,
jab_float *  module_size,
jab_int32 *  dir 
)

Crosscheck the alignment pattern.

Parameters
chthe binarized color channels of the image
ythe y coordinate of the horizontal scanline
minxthe minimal coordinate of the horizontal scanline
maxxthe maximal coordinate of the horizontal scanline
cur_xthe start position of the horizontal scanline
ap_typethe alignment pattern type
max_module_sizethe maximal allowed module size
centerxthe x coordinate of the alignment pattern center
centerythe y coordinate of the alignment pattern center
module_sizethe module size in horizontal direction
dirthe alignment pattern direction
Returns
JAB_SUCCESS | JAB_FAILURE
jab_boolean crossCheckPatternCh ( jab_bitmap ch,
jab_int32  type,
jab_int32  h_v,
jab_float  module_size_max,
jab_float *  module_size,
jab_float *  centerx,
jab_float *  centery,
jab_int32 *  dir,
jab_int32 *  dcc 
)

Crosscheck the finder pattern candidate in one channel.

Parameters
chthe binarized color channel
typethe finder pattern type
h_vthe direction of the candidate scanline, 0:horizontal 1:vertical
module_size_maxthe maximal allowed module size
module_sizethe module size in all directions
centerxthe x coordinate of the finder pattern center
centerythe y coordinate of the finder pattern center
dirthe finder pattern direction
dccthe diagonal crosscheck result
Returns
JAB_SUCCESS | JAB_FAILURE
jab_int32 crossCheckPatternDiagonal ( jab_bitmap image,
jab_int32  type,
jab_float  module_size_max,
jab_float *  centerx,
jab_float *  centery,
jab_float *  module_size,
jab_int32 *  dir,
jab_boolean  both_dir 
)

Crosscheck the finder pattern candidate in diagonal direction.

Parameters
imagethe image bitmap
typethe finder pattern type
module_size_maxthe maximal allowed module size
centerxthe x coordinate of the finder pattern center
centerythe y coordinate of the finder pattern center
module_sizethe module size in diagonal direction
dirthe finder pattern direction
both_dirscan both diagonal scanlines
Returns
the number of confirmed diagonal scanlines
jab_float crossCheckPatternDiagonalAP ( jab_bitmap image,
jab_int32  ap_type,
jab_int32  module_size_max,
jab_point  center,
jab_int32 *  dir 
)

Crosscheck the alignment pattern candidate in diagonal direction.

Parameters
imagethe image bitmap
ap_typethe alignment pattern type
module_size_maxthe maximal allowed module size
centerthe alignment pattern center
dirthe alignment pattern direction
Returns
the y coordinate of the diagonal scanline center | -1 if failed
jab_boolean crossCheckPatternHorizontal ( jab_bitmap image,
jab_float  module_size_max,
jab_float *  centerx,
jab_float  centery,
jab_float *  module_size 
)

Crosscheck the finder pattern candidate in horizontal direction.

Parameters
imagethe image bitmap
module_size_maxthe maximal allowed module size
centerxthe x coordinate of the finder pattern center
centerythe y coordinate of the finder pattern center
module_sizethe module size in horizontal direction
Returns
JAB_SUCCESS | JAB_FAILURE
jab_float crossCheckPatternHorizontalAP ( jab_byte *  row,
jab_int32  channel,
jab_int32  startx,
jab_int32  endx,
jab_int32  centerx,
jab_int32  ap_type,
jab_float  module_size_max,
jab_float *  module_size 
)

Crosscheck the alignment pattern candidate in horizontal direction.

Parameters
rowthe bitmap row
channelthe color channel
startxthe start position
endxthe end position
centerxthe center of the candidate scanline
ap_typethe alignment pattern type
module_size_maxthe maximal allowed module size
module_sizethe module size in horizontal direction
Returns
the x coordinate of the horizontal scanline center | -1 if failed
jab_boolean crossCheckPatternVertical ( jab_bitmap image,
jab_int32  module_size_max,
jab_float  centerx,
jab_float *  centery,
jab_float *  module_size 
)

Crosscheck the finder pattern candidate in vertical direction.

Parameters
imagethe image bitmap
module_size_maxthe maximal allowed module size
centerxthe x coordinate of the finder pattern center
centerythe y coordinate of the finder pattern center
module_sizethe module size in vertical direction
Returns
JAB_SUCCESS | JAB_FAILURE
jab_float crossCheckPatternVerticalAP ( jab_bitmap image,
jab_point  center,
jab_int32  module_size_max,
jab_float *  module_size 
)

Crosscheck the alignment pattern candidate in vertical direction.

Parameters
imagethe image bitmap
centerthe alignment pattern center
module_size_maxthe maximal allowed module size
module_sizethe module size in vertical direction
Returns
the y coordinate of the vertical scanline center | -1 if failed
jab_boolean decodeDockedSlaves ( jab_bitmap bitmap,
jab_bitmap ch[],
jab_decoded_symbol symbols,
jab_int32  host_index,
jab_int32 *  total 
)

Decode docked slave symbols around a host symbol.

Parameters
bitmapthe image bitmap
chthe binarized color channels of the image
symbolsthe symbol list
host_indexthe index number of the host symbol
totalthe number of symbols in the list
Returns
JAB_SUCCESS | JAB_FAILURE
jab_data* decodeJABCode ( jab_bitmap bitmap,
jab_int32  mode,
jab_int32 *  status 
)

Decode a JAB Code.

Parameters
bitmapthe image bitmap
modethe decoding mode(NORMAL_DECODE: only output completely decoded data when all symbols are correctly decoded COMPATIBLE_DECODE: also output partly decoded data even if some symbols are not correctly decoded
statusthe decoding status code (0: not detectable, 1: not decodable, 2: partly decoded with COMPATIBLE_DECODE mode, 3: fully decoded)
Returns
the decoded data | NULL if failed
jab_data* decodeJABCodeEx ( jab_bitmap bitmap,
jab_int32  mode,
jab_int32 *  status,
jab_decoded_symbol symbols,
jab_int32  max_symbol_number 
)

Extended function to decode a JAB Code.

Parameters
bitmapthe image bitmap
modethe decoding mode(NORMAL_DECODE: only output completely decoded data when all symbols are correctly decoded COMPATIBLE_DECODE: also output partly decoded data even if some symbols are not correctly decoded
statusthe decoding status code (0: not detectable, 1: not decodable, 2: partly decoded with COMPATIBLE_DECODE mode, 3: fully decoded)
symbolsthe decoded symbols
max_symbol_numberthe maximal possible number of symbols to be decoded
Returns
the decoded data | NULL if failed
jab_boolean detectMaster ( jab_bitmap bitmap,
jab_bitmap ch[],
jab_decoded_symbol master_symbol 
)

Detect and decode a master symbol.

Parameters
bitmapthe image bitmap
chthe binarized color channels of the image
master_symbolthe master symbol
Returns
JAB_SUCCESS | JAB_FAILURE
jab_bitmap* detectSlave ( jab_bitmap bitmap,
jab_bitmap ch[],
jab_decoded_symbol host_symbol,
jab_decoded_symbol slave_symbol,
jab_int32  docked_position 
)

Detect a slave symbol.

Parameters
bitmapthe image bitmap
chthe binarized color channels of the image
host_symbolthe host symbol
slave_symbolthe slave symbol
docked_positionthe docked position
Returns
the sampled slave symbol matrix | NULL if failed
jab_alignment_pattern findAlignmentPattern ( jab_bitmap ch[],
jab_float  x,
jab_float  y,
jab_float  module_size,
jab_int32  ap_type 
)

Find alignment pattern around a given position.

Parameters
chthe binarized color channels of the image
xthe x coordinate of the given position
ythe y coordinate of the given position
module_sizethe module size
ap_typethe alignment pattern type
Returns
the found alignment pattern
jab_finder_pattern* findMasterSymbol ( jab_bitmap ch[],
jab_detect_mode  mode 
)

Find the master symbol in the image.

Parameters
chthe binarized color channels of the image
modethe detection mode
Returns
the finder pattern list | NULL
jab_boolean findSlaveSymbol ( jab_bitmap bitmap,
jab_bitmap ch[],
jab_decoded_symbol host_symbol,
jab_decoded_symbol slave_symbol,
jab_int32  docked_position 
)

Find a docked slave symbol.

Parameters
bitmapthe image bitmap
chthe binarized color channels of the image
host_symbolthe host symbol
slave_symbolthe slave symbol
docked_positionthe docked position
Returns
JAB_SUCCESS | JAB_FAILURE
jab_finder_pattern getBestPattern ( jab_finder_pattern fps,
jab_int32  fp_count 
)

Find the finder pattern with most detected times.

Parameters
fpsthe finder pattern list
fp_countthe number of finder patterns in the list
jab_int32 getSideSize ( jab_int32  size,
jab_int32 *  flag 
)

Get the nearest valid side size to a given size.

Parameters
sizethe input size
flagthe flag indicating the magnitude of error
Returns
the nearest valid side size
void preprocessImage ( jab_bitmap bitmap)

Preprocess the image.

Parameters
bitmapthe image bitmap
void removeBadPatterns ( jab_finder_pattern fps,
jab_int32  fp_count,
jab_float  mean,
jab_float  threshold 
)

Remove the finder patterns with greatly different module size.

Parameters
fpsthe finder pattern list
fp_countthe number of finder patterns in the list
meanthe average module size
thresholdthe tolerance threshold
jab_bitmap* sampleSymbolByAlignmentPattern ( jab_bitmap bitmap,
jab_bitmap ch[],
jab_decoded_symbol symbol,
jab_alignment_pattern fps 
)

Sample a symbol with help of alignment patterns.

Parameters
bitmapthe image bitmap
chthe binarized color channels of the image
symbolthe symbol to be sampled
fpsthe finder/alignment patterns
Returns
the sampled symbol matrix | NULL if failed
jab_int32 saveAlignmentPattern ( jab_alignment_pattern ap,
jab_alignment_pattern aps,
jab_int32 *  counter 
)

Save a found alignment pattern into the alignment pattern list.

Parameters
apthe alignment pattern
apsthe alignment pattern list
counterthe number of alignment patterns in the list
Returns
-1 if added as a new alignment pattern | the alignment pattern index if combined with an existing pattern
void saveFinderPattern ( jab_finder_pattern fp,
jab_finder_pattern fps,
jab_int32 *  counter,
jab_int32 *  fp_type_count 
)

Save a found finder pattern into the finder pattern list.

Parameters
fpthe finder pattern
fpsthe finder pattern list
counterthe number of finder patterns in the list
fp_type_countthe number of finder pattern types in the list
void scanPatternVertical ( jab_bitmap ch[],
jab_int32  min_module_size,
jab_finder_pattern fps,
jab_int32 *  fp_type_count,
jab_int32 *  total_finder_patterns 
)

Scan the image vertically.

Parameters
chthe binarized color channels of the image
min_module_sizethe minimal module size
fpsthe found finder patterns
fp_type_countthe number of found finder patterns for each type
total_finder_patternsthe number of totally found finder patterns
jab_boolean seekPattern ( jab_bitmap ch,
jab_int32  row,
jab_int32  col,
jab_int32 *  start,
jab_int32 *  end,
jab_float *  center,
jab_float *  module_size,
jab_int32 *  skip 
)

Find a candidate scanline of finder pattern.

Parameters
chthe image channel
rowthe row to be scanned
colthe column to be scanned
startthe start position
endthe end position
centerthe center of the candidate scanline
module_sizethe module size
skipthe number of pixels to be skipped in the next scan
Returns
JAB_SUCCESS | JAB_FAILURE
jab_boolean seekPatternHorizontal ( jab_byte *  row,
jab_int32 *  startx,
jab_int32 *  endx,
jab_float *  centerx,
jab_float *  module_size,
jab_int32 *  skip 
)

Find a candidate horizontal scanline of finder pattern.

Parameters
rowthe bitmap row
startxthe start position
endxthe end position
centerxthe center of the candidate scanline
module_sizethe module size
skipthe number of pixels to be skipped in the next scan
Returns
JAB_SUCCESS | JAB_FAILURE
jab_int32 selectBestPatterns ( jab_finder_pattern fps,
jab_int32  fp_count,
jab_int32 *  fp_type_count 
)

Select the best finder patterns out of the list.

Parameters
fpsthe finder pattern list
fp_countthe number of finder patterns in the list
fp_type_countthe number of each finder pattern type
Returns
the number of missing finder pattern types