Permalink
Browse files

src/libdecodeqr/imagereader.cpp:

 * supported export code region and finder pattern information (track ticket:15) 
 * supported rotated image.  (track ticket:13 )

src/libdecodeqr/libdecodeqr.cpp:
 *supported export code region and finder pattern information (track ticket:15) 

src/sample/webcam.cpp:
 * add usage of qr_decoder_get_finderpattern_boxes() and qr_decoder_get_code

git-svn-id: http://www.koka-in.org/svn/libdecodeqr/trunk@33 d649fbcd-581f-0410-8d75-88b9247333c5
  • Loading branch information...
1 parent 262d827 commit 45a3259bc5b77fbd8ac5057d91974cefeed9a712 zophos committed Nov 26, 2006
@@ -197,7 +197,7 @@ extern int qr_decoder_get_header(QrDecoderHandle decoder,
/////////////////////////////////////////////////////////////////////////
//
-// get decoded data
+// get decoded text data
//
// ARGS:
// QrDecoderHandle decoder: handler
@@ -217,9 +217,37 @@ extern int qr_decoder_get_body(QrDecoderHandle decoder,
/////////////////////////////////////////////////////////////////////////
//
+// get vertexes of decoded code region
+//
+// ARGS:
+// QrDecoderHandle decoder: handler
+//
+// RETURN:
+// Pointer to CvPoint[4] which consist vertexes of code region
+//
+extern CvPoint *qr_decoder_get_coderegion_vertexes(QrDecoderHandle decoder);
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// get Box array of decoded finder patterns
+//
+// ARGS:
+// QrDecoderHandle decoder: handler
+//
+// RETURN:
+// Pointer to CvBox2D[3] which consist boxes of finder pattern
+//
+extern CvBox2D *qr_decoder_get_finderpattern_boxes(QrDecoderHandle decoder);
+
+
+/////////////////////////////////////////////////////////////////////////
+//
// version information
//
extern char *qr_decoder_version();
+extern char *qr_decoder_version_description();
+extern char *qr_decoder_version_product();
extern int qr_decoder_version_major();
extern int qr_decoder_version_minor();
extern int qr_decoder_version_teeny();
@@ -52,6 +52,9 @@ namespace Qr{
void ImageReader::_init()
{
+ memset(this->_coderegion_vertexes,0,sizeof(CvPoint)*4);
+ memset(this->_finderpattern_boxes,0,sizeof(CvBox2D)*3);
+
this->_img_src_internal=NULL;
this->_img_src=NULL;
this->_img_transformed=NULL;
@@ -144,6 +147,15 @@ namespace Qr{
{
return(this->_img_tmp_1c);
}
+ CvPoint *ImageReader::coderegion_vertexes()
+ {
+ return(this->_coderegion_vertexes);
+ }
+ CvBox2D *ImageReader::finderpattern_boxes()
+ {
+ return(this->_finderpattern_boxes);
+ }
+
Qr *ImageReader::decode(int adaptive_th_size,
int adaptive_th_delta)
@@ -195,6 +207,9 @@ namespace Qr{
this->qr=NULL;
}
+ memset(this->_coderegion_vertexes,0,sizeof(CvPoint)*4);
+ memset(this->_finderpattern_boxes,0,sizeof(CvBox2D)*3);
+
//
// binarize
//
@@ -436,7 +451,8 @@ namespace Qr{
int c=this->_seq_finder_pattern->total,i;
for(i=0;i<c;i++){
box=*(CvBox2D *)cvGetSeqElem(this->_seq_finder_pattern,i);
-
+ this->_finderpattern_boxes[i]=box;
+
//
// set 2-cells margin for fale-safe
//
@@ -491,8 +507,6 @@ namespace Qr{
//
// calcurate convex hull that assumed as code area
//
- //CvSeq *pts=this->_seq_tmp_points[1];
- //cvClearSeq(pts);
CvSeq *pts=cvCreateSeq(CV_SEQ_ELTYPE_POINT,
sizeof(CvSeq),sizeof(CvPoint),
this->_stor_tmp);
@@ -547,9 +561,10 @@ namespace Qr{
cvResetImageROI(dst);
//
- // get Centor of Gravity
+ // get code area's Centor of Gravity
//
- int c=this->_seq_code_area_contour->total,i;
+ int i;
+ int c=this->_seq_code_area_contour->total;
CvPoint2D32f cog;
cog.x=0.0F;
cog.y=0.0F;
@@ -566,7 +581,8 @@ namespace Qr{
// sort code_area_contour by clock-wise
//
cvSeqSort(this->_seq_code_area_contour,seq_cmp_by_clockwise,&cog);
-
+
+
//
// calculates matrix of perspective transform
//
@@ -576,31 +592,62 @@ namespace Qr{
//
CvPoint2D32f spts[4];
CvPoint2D32f dpts[4];
+ float max_d=0.0F;
+ int offset=0;
#ifdef _DEBUG
fprintf(stderr,"target region: ");
#endif
for(i=0;i<c;i++){
- spts[i]=cvPointTo32f(*(CvPoint *)cvGetSeqElem(
- this->_seq_code_area_contour,i));
+ this->_coderegion_vertexes[i]=*(CvPoint *)cvGetSeqElem(
+ this->_seq_code_area_contour,i);
+ spts[i]=cvPointTo32f(this->_coderegion_vertexes[i]);
+
+ //
+ // find nearest finder pattern
+ //
+ int j=0;
+ float tmp_d=0.0F;
+ float min_d=(this->_finderpattern_boxes[j].center.x-spts[i].x)*
+ (this->_finderpattern_boxes[j].center.x-spts[i].x)+
+ (this->_finderpattern_boxes[j].center.y-spts[i].y)*
+ (this->_finderpattern_boxes[j].center.y-spts[i].y);
+
+ for(j=1;j<3;j++){
+ tmp_d=(this->_finderpattern_boxes[j].center.x-spts[i].x)*
+ (this->_finderpattern_boxes[j].center.x-spts[i].x)+
+ (this->_finderpattern_boxes[j].center.y-spts[i].y)*
+ (this->_finderpattern_boxes[j].center.y-spts[i].y);
+
+ if(min_d>tmp_d)
+ min_d=tmp_d;
+ }
+ if(max_d<min_d){
+ max_d=min_d;
+ offset=i;
+ }
#ifdef _DEBUG
fprintf(stderr,"(%.0lf,%.0lf) ",spts[i].x,spts[i].y);
#endif
}
+
+ offset=(offset+2)%4;
+
#ifdef _DEBUG
- fprintf(stderr,"\n");
+ fprintf(stderr,", rotation offset=%d\n",offset);
#endif
-
+
float side_len=cvSqrt((spts[0].x-spts[1].x)*(spts[0].x-spts[1].x)+
(spts[0].y-spts[1].y)*(spts[0].y-spts[1].y));
- dpts[0]=spts[0];
- dpts[1].x=dpts[0].x+side_len;
- dpts[1].y=dpts[0].y;
- dpts[2].x=dpts[1].x;
- dpts[2].y=dpts[1].y+side_len;
- dpts[3].x=dpts[0].x;
- dpts[3].y=dpts[0].y+side_len;
+ for(i=0;i<4;i++)
+ dpts[i]=cvPoint2D32f(0.0,0.0);
+
+ dpts[(offset+1)%4].x+=side_len;
+ dpts[(offset+2)%4].x+=side_len;
+ dpts[(offset+2)%4].y+=side_len;
+ dpts[(offset+3)%4].y+=side_len;
+
CvMat *map=cvCreateMat(3,3,CV_64FC1);
cvWarpPerspectiveQMatrix(spts,dpts,map);
@@ -610,11 +657,11 @@ namespace Qr{
//
cvWarpPerspective(src,dst,map);
cvReleaseMat(&map);
-
+
//
// set ROI as code area
//
- CvRect roi=cvRect((int)dpts[0].x,(int)dpts[0].y,
+ CvRect roi=cvRect((int)dpts[offset].x,(int)dpts[offset].y,
(int)side_len+1,(int)side_len+1);
cvSetImageROI(dst,roi);
@@ -17,6 +17,7 @@
#endif
#include <cv.h>
+#include <memory.h>
#include "qrerror.h"
#include "container.h"
@@ -51,6 +52,8 @@ namespace Qr{
CvMemStorage *_stor_tmp;
CvSeq *_seq_finder_pattern;
CvSeq *_seq_code_area_contour;
+ CvPoint _coderegion_vertexes[4];
+ CvBox2D _finderpattern_boxes[3];
public:
ImageReader();
@@ -69,6 +72,8 @@ namespace Qr{
IplImage *transformed_buffer();
IplImage *binarized_buffer();
IplImage *tmp_buffer();
+ CvPoint *coderegion_vertexes();
+ CvBox2D *finderpattern_boxes();
Qr *decode(int adaptive_th_size=
DEFAULT_ADAPTIVE_TH_SIZE,
@@ -68,7 +68,6 @@ IplImage *qr_decoder_get_tmp_image_buffer(QrDecoderHandle decoder)
return(imagereader->tmp_buffer());
}
-
QrDecoderHandle qr_decoder_set_image_buffer(QrDecoderHandle decoder,
IplImage *src)
{
@@ -133,11 +132,31 @@ int qr_decoder_get_body(QrDecoderHandle decoder,
return(size);
}
+CvPoint *qr_decoder_get_coderegion_vertexes(QrDecoderHandle decoder)
+{
+ Qr::ImageReader *imagereader=(Qr::ImageReader *)decoder;
+ return(imagereader->coderegion_vertexes());
+}
+
+CvBox2D *qr_decoder_get_finderpattern_boxes(QrDecoderHandle decoder)
+{
+ Qr::ImageReader *imagereader=(Qr::ImageReader *)decoder;
+ return(imagereader->finderpattern_boxes());
+}
+
char *qr_decoder_version()
{
return(LIBDECODEQR_VERSION);
}
+char *qr_decoder_version_description()
+{
+ return(LIBDECODEQR_VERSION_DESCRIPTION);
+}
+char *qr_decoder_version_product()
+{
+ return(LIBDECODEQR_PRODUCTNAME);
+}
int qr_decoder_version_major()
{
return(LIBDECODEQR_VERSION_MAJOR);
Deleted file not rendered
@@ -1,22 +1,21 @@
# Microsoft Developer Studio Generated NMAKE File, Based on simple.dsp
!IF "$(CFG)" == ""
CFG=simple - Win32 Debug
-!MESSAGE 構成が指定されていません。デフォルトの simple - Win32 Debug を設定します。
+!MESSAGE Missing target. Using defualt "simple - Win32 Debug".
!ENDIF
!IF "$(CFG)" != "simple - Win32 Release" && "$(CFG)" != "simple - Win32 Debug"
-!MESSAGE 指定された ビルド モード "$(CFG)" は正しくありません。
-!MESSAGE NMAKE の実行時に構成を指定できます
-!MESSAGE コマンド ライン上でマクロの設定を定義します。例:
+!MESSAGE Mode "$(CFG)" is not valid.
!MESSAGE
-!MESSAGE NMAKE /f "simple.mak" CFG="simple - Win32 Debug"
+!MESSAGE Valid modes are:
!MESSAGE
-!MESSAGE 選択可能なビルド モード:
+!MESSAGE "simple - Win32 Release" (for "Win32 (x86) Static Library")
+!MESSAGE "simple - Win32 Debug" (for "Win32 (x86) Static Library")
!MESSAGE
-!MESSAGE "simple - Win32 Release" ("Win32 (x86) Console Application" 用)
-!MESSAGE "simple - Win32 Debug" ("Win32 (x86) Console Application" 用)
+!MESSAGE eg:
!MESSAGE
-!ERROR 無効な構成が指定されています。
+!MESSAGE NMAKE /f "simple.mak" CFG="webcam - Win32 Debug"
+!ERROR Invalid target are gaven.
!ENDIF
!IF "$(OS)" == "Windows_NT"
@@ -103,7 +103,41 @@ int main(int argc,char *argv[])
qr_decoder_get_body(decoder,text,text_size);
printf("%s\n\n",text);
- key=cvWaitKey(1000);
+ //
+ // draw found code region with green line
+ //
+ CvPoint *vertexes=qr_decoder_get_coderegion_vertexes(decoder);
+ CvPoint pt=vertexes[3];
+ int i;
+ for(i=0;i<4;i++){
+ cvLine(src,pt,vertexes[i],CV_RGB(0,255,0),3);
+ pt=vertexes[i];
+ }
+
+ //
+ // draw found finder patterns with green ellipse
+ //
+ CvBox2D *boxes=qr_decoder_get_finderpattern_boxes(decoder);
+ for(i=0;i<3;i++){
+ CvSize sz=cvSize((int)boxes[i].size.width/2,
+ (int)boxes[i].size.height/2);
+ cvEllipse(src,
+ cvPointFrom32f(boxes[i].center),
+ sz,
+ boxes[i].angle,
+ 0,360,
+ CV_RGB(0,255,0),2);
+ }
+
+ if(src->origin)
+ cvConvertImage(src,src,CV_CVTIMG_FLIP);
+
+ cvShowImage("src",src);
+
+ //
+ // wait 1500msec.
+ //
+ key=cvWaitKey(1500);
}
}
@@ -0,0 +1,15 @@
+# Microsoft Developer Studio Generated Dependency File, included by webcam.mak
+
+.\webcam.cpp : \
+ "..\..\..\..\..\..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cv\include\cv.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cv\include\cvcompat.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cv\include\cvtypes.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cxcore\include\cxcore.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cxcore\include\cxerror.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\cxcore\include\cxtypes.h"\
+ "..\..\..\..\..\..\..\..\program files\opencv\otherlibs\highgui\highgui.h"\
+ "..\..\libdecodeqr\decodeqr.h"\
+ "..\..\libdecodeqr\qrerror.h"\
+ "..\..\libdecodeqr\qrtypes.h"\
+
Oops, something went wrong.

0 comments on commit 45a3259

Please sign in to comment.