/src/sample/simple/simpletest.cpp

https://github.com/jcbolor/libdecodeqr · C++ · 70 lines · 26 code · 9 blank · 35 comment · 1 complexity · 603f991f8b53c6843920a303a9ac7bbb MD5 · raw file

  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // simpletest.cpp --a part of libdecodeqr
  4. //
  5. // Copyright(C) 2007 NISHI Takao <zophos@koka-in.org>
  6. // JMA (Japan Medical Association)
  7. // NaCl (Network Applied Communication Laboratory Ltd.)
  8. //
  9. // This is free software with ABSOLUTELY NO WARRANTY.
  10. // You can redistribute and/or modify it under the terms of LGPL.
  11. //
  12. // $Id$
  13. //
  14. #include <stdio.h>
  15. #include <highgui.h>
  16. #include "../../libdecodeqr/decodeqr.h"
  17. int main(int argc,char *argv[])
  18. {
  19. cvNamedWindow("src",1);
  20. //
  21. // load image
  22. //
  23. IplImage *src=cvLoadImage(argv[1],1);
  24. cvShowImage("src",src);
  25. //
  26. // show version info
  27. //
  28. printf("libdecodeqr version %s\n",qr_decoder_version());
  29. //
  30. // initialize
  31. //
  32. QrDecoderHandle decoder=qr_decoder_open();
  33. //
  34. // do decode using default parameter
  35. //
  36. short stat=qr_decoder_decode_image(decoder,src);
  37. printf("STATUS=%04x\n",stat);
  38. //
  39. // get QR code header
  40. //
  41. QrCodeHeader header;
  42. if(qr_decoder_get_header(decoder,&header)){
  43. //
  44. // get QR code text
  45. // To null terminate, a buffer size is larger than body size.
  46. //
  47. char *buf=new char[header.byte_size+1];
  48. qr_decoder_get_body(decoder,(unsigned char *)buf,header.byte_size+1);
  49. printf("%s\n",buf);
  50. }
  51. //
  52. // finalize
  53. //
  54. qr_decoder_close(decoder);
  55. puts("");
  56. puts("Hit any key to end.");
  57. cvWaitKey(0);
  58. cvDestroyAllWindows();
  59. cvReleaseImage(&src);
  60. return(0);
  61. }