Tizen Native API  7.0
Media Vision BarCode

Barcode module consists of barcode detection and barcode generation submodules.

Required Header

#include <mv_barcode.h>

Related Features

This API is related with the following features:

  • http://tizen.org/feature/vision.barcode_detection
  • http://tizen.org/feature/vision.barcode_generation

It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.

Overview

Media Vision BarCode contains two submodules:
* Detection submodule, * Generation submodule.

Detection submodule can be used for detecting barcodes on image sources, reading encoded messages, getting barcode types.
This module contains mv_barcode_detect() function and mv_barcode_detected_cb() callback. mv_barcode_detect() function can be called for the image determined by mv_source_h handler to detect barcodes. If barcodes were detected, then mv_barcode_detected_cb() callback is called. Each detected barcode type, message and location can be processed by this callback. mv_barcode_detect() supports ROI (rectangular region of interest) specification to allow barcode detection only for the region on the image.

Generation submodule can be used for generating the barcodes and QR codes. Different encoding types (see mv_barcode_qr_mode_e), error correction codes (see mv_barcode_qr_ecc_e) and code versions are supported for QRCodes.
This submodule contains mv_barcode_generate_source() function to generate handler to the buffer with row image of barcode, and mv_barcode_generate_image() function to generate image file with barcode. Both functions support the set of parameters which allow API user to configure output barcode. QR codes as well as Barcodes are supported (see mv_barcode_type_e enumeration for full list of supported barcodes). For QR codes it is possible to specify error correction code and encoding mode (see mv_barcode_qr_mode_e). Generation to file supports several formats (see mv_barcode_image_format_e).

Functions

int mv_barcode_detect (mv_source_h source, mv_engine_config_h engine_cfg, mv_rectangle_s roi, mv_barcode_detected_cb detect_cb, void *user_data)
 Detects barcode(s) on source and reads message from it.
int mv_barcode_generate_source (mv_engine_config_h engine_cfg, const char *message, mv_barcode_type_e type, mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version, mv_source_h image)
 Generates mv_source_h with barcode image.
int mv_barcode_generate_image (mv_engine_config_h engine_cfg, const char *message, int image_width, int image_height, mv_barcode_type_e type, mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version, const char *image_path, mv_barcode_image_format_e image_format)
 Generates image file with barcode.

Typedefs

typedef void(* mv_barcode_detected_cb )(mv_source_h source, mv_engine_config_h engine_cfg, const mv_quadrangle_s *barcode_locations, const char *messages[], const mv_barcode_type_e *types, int number_of_barcodes, void *user_data)
 Called when barcode detection is completed.

Defines

#define MV_BARCODE_DETECT_ATTR_TARGET   "MV_BARCODE_DETECT_ATTR_TARGET"
 Define MV_BARCODE_DETECT_ATTR_TARGET to set target attribute of the engine configuration.
#define MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES   "MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES"
 Use MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES to set rotation degree attribute of the engine configuration.
#define MV_BARCODE_DETECT_ATTR_ROTATION_COUNT   "MV_BARCODE_DETECT_ATTR_ROTATION_COUNT"
 Use MV_BARCODE_DETECT_ATTR_ROTATION_COUNT to set rotation count attribute of the engine configuration.
#define MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION   "MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION"
 Use MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION to set rotation direction attribute of the engine configuration.
#define MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT   "MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT"
 Use MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT to enable image quality enhancement attribute of the engine configuration.
#define MV_BARCODE_GENERATE_ATTR_TEXT   "MV_BARCODE_GENERATE_ATTR_TEXT"
 Define MV_BARCODE_GENERATE_ATTR_TEXT to set text attribute of the engine configuration.
#define MV_BARCODE_GENERATE_ATTR_COLOR_FRONT   "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT"
 Defines MV_BARCODE_GENERATE_ATTR_COLOR_FRONT to set Barcode's foreground color attribute of the engine configuration.
#define MV_BARCODE_GENERATE_ATTR_COLOR_BACK   "MV_BARCODE_GENERATE_ATTR_COLOR_BACK"
 Defines MV_BARCODE_GENERATE_ATTR_COLOR_BACK to set Barcode's background color attribute of the engine configuration.

Define Documentation

#define MV_BARCODE_DETECT_ATTR_ROTATION_COUNT   "MV_BARCODE_DETECT_ATTR_ROTATION_COUNT"

Use MV_BARCODE_DETECT_ATTR_ROTATION_COUNT to set rotation count attribute of the engine configuration.

If MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES, MV_BARCODE_DETECT_ATTR_ROTATION_COUNT, and MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION are set to 20, 9, and MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE, respectively,
detection will be tried with 20, 40, 60, ... 180 degrees as well as 0 degrees.
Similarly, -20, -40, -60, ... will be tried for MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE and -20, +20, -40, +40, ... will be tried iteratively for MV_BARCODE_DETECT_ATTR_ROTATION_ALL.

Since :
6.5
See also:
MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES
MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION
mv_barcode_detect_attr_rotation_direction_e
#define MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES   "MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES"

Use MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES to set rotation degree attribute of the engine configuration.

Since :
6.5
See also:
MV_BARCODE_DETECT_ATTR_ROTATION_COUNT
MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION
#define MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION   "MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION"
#define MV_BARCODE_DETECT_ATTR_TARGET   "MV_BARCODE_DETECT_ATTR_TARGET"

Define MV_BARCODE_DETECT_ATTR_TARGET to set target attribute of the engine configuration.

Since :
2.4
See also:
mv_barcode_detect_attr_target_e Target: 0-all, 1-1D, 2-2D
#define MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT   "MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT"

Use MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT to enable image quality enhancement attribute of the engine configuration.

Since :
6.5
#define MV_BARCODE_GENERATE_ATTR_COLOR_BACK   "MV_BARCODE_GENERATE_ATTR_COLOR_BACK"

Defines MV_BARCODE_GENERATE_ATTR_COLOR_BACK to set Barcode's background color attribute of the engine configuration.

Since :
3.0
Remarks:
This attribute represents RGB color as a hex triplet with six digits.
#define MV_BARCODE_GENERATE_ATTR_COLOR_FRONT   "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT"

Defines MV_BARCODE_GENERATE_ATTR_COLOR_FRONT to set Barcode's foreground color attribute of the engine configuration.

Since :
3.0
Remarks:
This attribute represents RGB color as a hex triplet with six digits.
#define MV_BARCODE_GENERATE_ATTR_TEXT   "MV_BARCODE_GENERATE_ATTR_TEXT"

Define MV_BARCODE_GENERATE_ATTR_TEXT to set text attribute of the engine configuration.

Since :
2.4
Remarks:
This attribute is only available for 1D barcode generation
See also:
mv_barcode_generate_attr_text_e Text: 0-invisible, 1-visible

Typedef Documentation

typedef void(* mv_barcode_detected_cb)(mv_source_h source, mv_engine_config_h engine_cfg, const mv_quadrangle_s *barcode_locations, const char *messages[], const mv_barcode_type_e *types, int number_of_barcodes, void *user_data)

Called when barcode detection is completed.

If no barcode is detected then the method will be called, barcodes and states will be equal to NULL, and number_of_barcodes - 0.

Since :
2.4
Parameters:
[in]sourceThe handle to the media source
[in]engine_cfgThe handle to the configuration of the engine
[in]barcode_locationsThe quadrangle locations of detected barcodes
[in]messagesThe decoded messages of barcodes
[in]typesThe types of detected barcodes
[in]number_of_barcodesThe number of detected barcodes
[in]user_dataThe user data passed from the mv_barcode_detect() function
Precondition:
mv_barcode_detect() invokes this callback
See also:
mv_barcode_detect()

Enumeration Type Documentation

Enumeration for rotation direction attribute.

Set one of rotation direction, which are:
MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE - clockwise rotation,
MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE - counter clockwise rotation,
MV_BARCODE_DETECT_ATTR_ROTATION_ALL - clockwise and counter clockwise rotation iteratively.

Since :
6.5
See also:
MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION
MV_BARCODE_DETECT_ATTR_ROTATION_COUNT
Enumerator:
MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE 

Clockwise

MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE 

Counter clockwise

MV_BARCODE_DETECT_ATTR_ROTATION_ALL 

Clockwise and counter clockwise

Enumeration to target attribute.

Since :
2.4
Enumerator:
MV_BARCODE_DETECT_ATTR_TARGET_ALL 

1D and 2D

MV_BARCODE_DETECT_ATTR_TARGET_1D_BARCODE 

1D barcode only

MV_BARCODE_DETECT_ATTR_TARGET_2D_BARCODE 

2D barcode only

Enumeration to text attribute.

Since :
2.4
Enumerator:
MV_BARCODE_GENERATE_ATTR_TEXT_INVISIBLE 

Invisible

MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE 

Visible

Enumeration for supported image formats for the barcode generating.

Since :
2.4
Enumerator:
MV_BARCODE_IMAGE_FORMAT_UNAVAILABLE 

Unavailable image format

MV_BARCODE_IMAGE_FORMAT_BMP 

BMP image format

MV_BARCODE_IMAGE_FORMAT_JPG 

JPEG image format

MV_BARCODE_IMAGE_FORMAT_PNG 

PNG image format

MV_BARCODE_IMAGE_FORMAT_NUM 

The number of supported image format

Enumeration for supported QR code error correction level.

Since :
2.4
Remarks:
This is unavailable for 1D barcodes
Enumerator:
MV_BARCODE_QR_ECC_LOW 

Recovery up to 7% losses

MV_BARCODE_QR_ECC_MEDIUM 

Recovery up to 15% losses

MV_BARCODE_QR_ECC_QUARTILE 

Recovery up to 25% losses

MV_BARCODE_QR_ECC_HIGH 

Recovery up to 30% losses

MV_BARCODE_QR_ECC_UNAVAILABLE 

Unavailable

Enumeration for supported QR code encoding mode.

Since :
2.4
Remarks:
This is unavailable for 1D barcodes
Enumerator:
MV_BARCODE_QR_MODE_NUMERIC 

Numeric digits

MV_BARCODE_QR_MODE_ALPHANUMERIC 

Alphanumeric characters

MV_BARCODE_QR_MODE_BYTE 

Raw 8-bit bytes

MV_BARCODE_QR_MODE_UTF8 

UTF-8 character encoding

MV_BARCODE_QR_MODE_UNAVAILABLE 

Unavailable

Enumeration for supported barcode types.

QR codes (versions 1 to 40) and set of 1D barcodes are supported

Since :
2.4
Remarks:
MV_BARCODE_UNDEFINED is deprecated. Use MV_BARCODE_UNKNOWN instead
Enumerator:
MV_BARCODE_QR 

2D barcode - Quick Response code

MV_BARCODE_UPC_A 

1D barcode - Universal Product Code with 12-digit

MV_BARCODE_UPC_E 

1D barcode - Universal Product Code with 6-digit

MV_BARCODE_EAN_8 

1D barcode - International Article Number with 8-digit

MV_BARCODE_EAN_13 

1D barcode - International Article Number with 13-digit

MV_BARCODE_CODE128 

1D barcode - Code 128

MV_BARCODE_CODE39 

1D barcode - Code 39

MV_BARCODE_I2_5 

1D barcode - Interleaved Two of Five

MV_BARCODE_UNDEFINED 
Deprecated:
Undefined (Deprecated since 6.0)
MV_BARCODE_EAN_2 

1D barcode - International Article Number with 2-digit(add-on) (since 6.0)

MV_BARCODE_EAN_5 

1D barcode - International Article Number with 5-digit(add-on) (since 6.0)

MV_BARCODE_CODE93 

1D barcode - Code 93 (since 6.0)

MV_BARCODE_CODABAR 

1D barcode - CODABAR (since 6.0)

MV_BARCODE_DATABAR 

1D barcode - GS1 DATABAR (since 6.0)

MV_BARCODE_DATABAR_EXPAND 

1D barcode - GS1 DATABAR EXPAND(since 6.0)

MV_BARCODE_UNKNOWN 

Unknown (since 6.0)


Function Documentation

int mv_barcode_detect ( mv_source_h  source,
mv_engine_config_h  engine_cfg,
mv_rectangle_s  roi,
mv_barcode_detected_cb  detect_cb,
void *  user_data 
)

Detects barcode(s) on source and reads message from it.

Since :
2.4
Parameters:
[in]sourceThe media source handle
[in]engine_cfgThe handle to the configuration of the engine
[in]roiRegion of interest - rectangular area on the source which will be used for barcode detection Note that roi should be inside area on the source.
[in]detect_cbThe callback for result handling
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIA_VISION_ERROR_NONESuccessful
MEDIA_VISION_ERROR_INVALID_PARAMETERInvalid parameter
MEDIA_VISION_ERROR_NOT_SUPPORTEDNot supported
MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMATNot supported format
MEDIA_VISION_ERROR_INTERNALInternal error
Precondition:
Create a source handle by calling mv_create_source()
Create an engine configuration handle by calling mv_create_engine_config(), otherwise use NULL
See also:
mv_barcode_detected_cb()
int mv_barcode_generate_image ( mv_engine_config_h  engine_cfg,
const char *  message,
int  image_width,
int  image_height,
mv_barcode_type_e  type,
mv_barcode_qr_mode_e  qr_enc_mode,
mv_barcode_qr_ecc_e  qr_ecc,
int  qr_version,
const char *  image_path,
mv_barcode_image_format_e  image_format 
)

Generates image file with barcode.

Pay attention that for EAN-8 and EAN-13 barcode types the barcode type may be selected automatically and this selection depends on the input message length. Also for QR codes the version may be selected as minimum required to generate QR code with the input message length.

Since :
2.4
Remarks:
If the text attribute of engine configuration is set to MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE, MEDIA_VISION_ERROR_INVALID_OPERATION will be returned when type is MV_BARCODE_QR
The mediastorage privilege http://tizen.org/privilege/mediastorage is needed
if image_path is relevant to media storage.
The externalstorage privilege http://tizen.org/privilege/externalstorage is needed
if image_path is relevant to external storage.
Parameters:
[in]engine_cfgThe handle to the configuration of the engine
[in]messageThe message to be encoded in the barcode
[in]image_widthThe width of the generated image
[in]image_heightThe height of the generated image
[in]typeType of the barcode to be generated
[in]qr_enc_modeEncoding mode for the message (only for QR codes; for 1D barcodes set this parameter to MV_BARCODE_QR_MODE_UNAVAILABLE)
[in]qr_eccError correction level (only for QR codes; for 1D barcodes set this parameter to MV_BARCODE_QR_ECC_UNAVAILABLE)
[in]qr_versionQR code version (for 1D barcodes set this parameter to 0)
[in]image_pathThe path to the file that has to be generated
[in]image_formatThe format of the output image
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIA_VISION_ERROR_NONESuccessful
MEDIA_VISION_ERROR_INVALID_PARAMETERInvalid parameter
MEDIA_VISION_ERROR_MSG_TOO_LONGToo long or short message
MEDIA_VISION_ERROR_PERMISSION_DENIEDPermission denied
MEDIA_VISION_ERROR_NOT_SUPPORTEDNot supported
MEDIA_VISION_ERROR_INVALID_DATAInvalid data
MEDIA_VISION_ERROR_INVALID_PATHInvalid path
MEDIA_VISION_ERROR_INTERNALInternal error
MEDIA_VISION_ERROR_INVALID_OPERATIONInvalid operation
Precondition:
Create an engine configuration handle by calling mv_create_engine_config(), otherwise use NULL
See also:
mv_barcode_generate_source()
int mv_barcode_generate_source ( mv_engine_config_h  engine_cfg,
const char *  message,
mv_barcode_type_e  type,
mv_barcode_qr_mode_e  qr_enc_mode,
mv_barcode_qr_ecc_e  qr_ecc,
int  qr_version,
mv_source_h  image 
)

Generates mv_source_h with barcode image.

Pay attention that for EAN-8 and EAN-13 barcode types the barcode type may be selected automatically and this selection depends on the input message length. Also for QR codes the version may be selected as minimum required to generate QR code with the input message length.

Since :
2.4
Remarks:
If the text attribute of engine configuration is set to MV_BARCODE_GENERATE_ATTR_TEXT_VISIBLE, MEDIA_VISION_ERROR_INVALID_OPERATION will be returned when type is MV_BARCODE_QR
Parameters:
[in]engine_cfgThe handle to the configuration of the engine
[in]messageThe message to be encoded in the barcode
[in]typeType of the barcode to be generated
[in]qr_enc_modeEncoding mode for the message (only for QR codes; for 1D barcodes set this parameter to MV_BARCODE_QR_MODE_UNAVAILABLE)
[in]qr_eccError correction level (only for QR codes; for 1D barcodes set this parameter to MV_BARCODE_QR_ECC_UNAVAILABLE)
[in]qr_versionQR code version (for 1D barcodes set this parameter to 0)
[in,out]imageThe media source handle which will be used to fill by the buffer with generated image
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIA_VISION_ERROR_NONESuccessful
MEDIA_VISION_ERROR_INVALID_PARAMETERInvalid parameter
MEDIA_VISION_ERROR_MSG_TOO_LONGToo long or short message
MEDIA_VISION_ERROR_NOT_SUPPORTEDNot supported
MEDIA_VISION_ERROR_INVALID_DATAInvalid data
MEDIA_VISION_ERROR_INTERNALInternal error
MEDIA_VISION_ERROR_INVALID_OPERATIONInvalid operation
Precondition:
Create an engine configuration handle by calling mv_create_engine_config(), otherwise use NULL
See also:
mv_barcode_generate_image()