diff --git a/Emgu.CV.Extern/objdetect/QRCodeDetector.cpp b/Emgu.CV.Extern/objdetect/QRCodeDetector.cpp index 5adb163d2..5895b76f4 100644 --- a/Emgu.CV.Extern/objdetect/QRCodeDetector.cpp +++ b/Emgu.CV.Extern/objdetect/QRCodeDetector.cpp @@ -65,9 +65,19 @@ void cveQRCodeDetectorArucoRelease(cv::QRCodeDetectorAruco** detector) #endif } -cv::QRCodeEncoder* cveQRCodeEncoderCreate(cv::Ptr** sharedPtr) -{ -#ifdef HAVE_OPENCV_OBJDETECT +cv::QRCodeEncoder* cveQRCodeEncoderCreate( + cv::Ptr** sharedPtr, + int version, + int correctionLevel, + int mode, + int structureNumber) +{ +#ifdef HAVE_OPENCV_OBJDETECT + cv::QRCodeEncoder::Params p; + p.version = version; + p.correction_level = static_cast(correctionLevel); + p.mode = static_cast(mode); + p.structure_number = structureNumber; cv::Ptr ptr = cv::QRCodeEncoder::create(); *sharedPtr = new cv::Ptr(ptr); return ptr.get(); @@ -87,7 +97,7 @@ void cveQRCodeEncoderRelease(cv::QRCodeEncoder** encoder, cv::Ptrencode(*encodedInfo, *qrcode); diff --git a/Emgu.CV.Extern/objdetect/objdetect_c.h b/Emgu.CV.Extern/objdetect/objdetect_c.h index 911acee14..8dd5d9e5f 100644 --- a/Emgu.CV.Extern/objdetect/objdetect_c.h +++ b/Emgu.CV.Extern/objdetect/objdetect_c.h @@ -117,9 +117,14 @@ CVAPI(void) cveQRCodeDetectorRelease(cv::QRCodeDetector** detector); CVAPI(void) cveQRCodeDetectorDecodeCurved(cv::QRCodeDetector* detector, cv::_InputArray* img, cv::_InputArray* points, cv::String* decodedInfo, cv::_OutputArray* straightCode); CVAPI(int) cveQRCodeDetectorGetEncoding(cv::QRCodeDetector* detector, int codeIdx); -CVAPI(cv::QRCodeEncoder*) cveQRCodeEncoderCreate(cv::Ptr** sharedPtr); +CVAPI(cv::QRCodeEncoder*) cveQRCodeEncoderCreate( + cv::Ptr** sharedPtr, + int version, + int correctionLevel, + int mode, + int structureNumber); CVAPI(void) cveQRCodeEncoderRelease(cv::QRCodeEncoder** encoder, cv::Ptr** sharedPtr); -CVAPI(void) cveQRCodeEncode(cv::QRCodeEncoder* encoder, cv::String* encodedInfo, cv::_OutputArray* qrcode); +CVAPI(void) cveQRCodeEncoderEncode(cv::QRCodeEncoder* encoder, cv::String* encodedInfo, cv::_OutputArray* qrcode); CVAPI(cv::QRCodeDetectorAruco*) cveQRCodeDetectorArucoCreate(cv::GraphicalCodeDetector** graphicalCodeDetector); CVAPI(void) cveQRCodeDetectorArucoRelease(cv::QRCodeDetectorAruco** detector); diff --git a/Emgu.CV.Test/AutoTestVarious.cs b/Emgu.CV.Test/AutoTestVarious.cs index 137b81189..89aac1ba6 100644 --- a/Emgu.CV.Test/AutoTestVarious.cs +++ b/Emgu.CV.Test/AutoTestVarious.cs @@ -4348,8 +4348,14 @@ namespace Emgu.CV.Test } [Test] - public void TestQCCode() + public void TestQRCode() { + using (QRCodeEncoder encoder = new QRCodeEncoder()) + using (Mat qrcodeImg = new Mat()) + { + encoder.Encode("https://www.emgu.com", qrcodeImg); + } + using (Mat m = EmguAssert.LoadMat("link_github_ocv.jpg")) using (QRCodeDetector detector = new QRCodeDetector()) using (VectorOfPoint pts = new VectorOfPoint()) @@ -4359,6 +4365,7 @@ namespace Emgu.CV.Test String text = detector.Decode(m, pts); } } + } [Test] diff --git a/Emgu.CV/Objdetect/QRCodeEncoder.cs b/Emgu.CV/Objdetect/QRCodeEncoder.cs index 35bcef15d..25970ddd7 100644 --- a/Emgu.CV/Objdetect/QRCodeEncoder.cs +++ b/Emgu.CV/Objdetect/QRCodeEncoder.cs @@ -18,6 +18,82 @@ namespace Emgu.CV /// public partial class QRCodeEncoder : SharedPtrObject { + /// + /// Specifies the encoding mode for the QR Code encoder. + /// + public enum EncodeMode + { + /// + /// Automatically selects the most suitable encoding mode based on the input data. + /// + Auto = -1, + /// + /// Represents the numeric encoding mode for the QR Code encoder. + /// This mode is used to encode numeric data (digits 0-9) efficiently, + /// allowing up to 3 digits to be encoded per byte. + /// + Numeric = 1, // 0b0001 + /// + /// Represents the alphanumeric encoding mode for the QR Code encoder. + /// + /// + /// This mode allows encoding of alphanumeric characters, including digits (0-9), + /// uppercase letters (A-Z), and a limited set of special characters + /// (space, $, %, *, +, -, ., /, :). + /// + Alphanumeric = 2, // 0b0010 + /// + /// Represents the Byte encoding mode for the QR Code encoder. + /// This mode allows encoding data in 8-bit byte format, supporting a wide range of characters. + /// + Byte = 4, // 0b0100 + /// + /// Specifies the Extended Channel Interpretation (ECI) encoding mode for the QR Code encoder. + /// This mode allows the inclusion of character sets or encodings beyond the default QR Code character set. + /// + Eci = 7, // 0b0111 + /// + /// Specifies the Kanji encoding mode for the QR Code encoder. + /// + /// + /// This mode is used to encode characters in the Shift JIS character set, + /// which is commonly used for Japanese text. It allows efficient encoding + /// of Kanji characters into QR codes. + /// + Kanji = 8, // 0b1000 + /// + /// Represents the Structured Append encoding mode for the QR Code encoder. + /// + /// + /// The Structured Append mode allows multiple QR codes to be combined into a single logical message. + /// This is useful when the data to be encoded exceeds the capacity of a single QR code. + /// + StructuredAppend = 3 // 0b0011 + } + + /// + /// Specifies the error correction levels for QR codes. + /// + public enum CorrectionLevel + { + /// + /// Low error correction level. Recovers approximately 7% of data. + /// + L = 0, + /// + /// Medium error correction level. Recovers approximately 15% of data. + /// + M = 1, + /// + /// Quartile error correction level. Recovers approximately 25% of data. + /// + Q = 2, + /// + /// High error correction level. Recovers approximately 30% of data. + /// + H = 3 + }; + /// /// Specifies the Extended Channel Interpretations (ECI) encodings supported by the QR Code encoder. /// @@ -30,7 +106,7 @@ namespace Emgu.CV public enum ECIEncodings { /// - /// + /// Represents the Shift JIS encoding, which is a character encoding for the Japanese language. /// ShiftJis = 20, /// @@ -42,9 +118,34 @@ namespace Emgu.CV /// /// Initializes a new instance of the class. /// - public QRCodeEncoder() + /// + /// The version of the QR code to generate. A value of 0 indicates automatic version selection. + /// + /// + /// The error correction level for the QR code. This determines the level of error correction + /// applied to the QR code. Possible values are , + /// , , and . + /// + /// + /// The encoding mode for the QR code. This specifies the type of data to encode, such as + /// numeric, alphanumeric, byte, or kanji. Possible values are defined in . + /// + /// + /// The structure number for structured append mode. This is used when the QR code is part of + /// a structured append sequence. Default is 1. + /// + public QRCodeEncoder( + int version = 0, + QRCodeEncoder.CorrectionLevel correctionLevel = CorrectionLevel.L, + QRCodeEncoder.EncodeMode mode = EncodeMode.Auto, + int structureNumber = 1) { - _ptr = ObjdetectInvoke.cveQRCodeEncoderCreate(ref _sharedPtr); + _ptr = ObjdetectInvoke.cveQRCodeEncoderCreate( + ref _sharedPtr, + version, + correctionLevel, + mode, + structureNumber); } /// @@ -79,7 +180,12 @@ namespace Emgu.CV public static partial class ObjdetectInvoke { [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] - internal static extern IntPtr cveQRCodeEncoderCreate(ref IntPtr sharedPtr); + internal static extern IntPtr cveQRCodeEncoderCreate( + ref IntPtr sharedPtr, + int version, + QRCodeEncoder.CorrectionLevel correctionLevel, + QRCodeEncoder.EncodeMode mode, + int structureNumber); [DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] internal static extern void cveQRCodeEncoderRelease(ref IntPtr ptr, ref IntPtr sharedPtr);