• Alvaro

    Hi Eric,

    I have found this article very interesting. I am trying to build an Android app with OpenCV native functions and I was wondering if you could share your code for the QR code localization and perspective correction with me.

    Thanks in advance,


    • kapil

      Hii Eric

      i need a favor from u. i m creating a android project on the same , but facing some difficulty . if u don’t mind can i have ur code as a reference


  • Amir

    this article helped me to find a way for doing my project! i’m implementing the flag detection part right now but I think the part where you said “we can find which of the contours are inside other contours,” is really time consuming (OR am I wrong) consider we have 500 contours then the loop will execute 499*499+ checking all points in each contours !

    for (int i=0; i<contours.size()-1; i++)
    for (int j=1; j100&&contours[j].size()>100)
    if (contours[i].size()>contours[j].size())
    //check if (contours j) is inside
    else if(contours[i].size()<contours[j].size())
    //check if (contours i) is inside

    would you pls give me some guidance ?

    • Eric

      Hey Amir,

      Yes it is time-consuming, and maybe we are able to use something like dynamic programming, say we already know that contour_a is inside contour_b, and contour_b is inside contour_c, in this case, we can know contour_a must be inside contour_c. Besides, the above trick maybe works better if we randomize the vector of contours before the 2-layers loop (still 2-layers loop, but maybe much faster).

      • Amir

        thanks a lot for your help 😉
        In my project I have to detect a rectangle in the image and extract some transformation parameters ; fortunately the camera will not move after that and I can run the main process which is in real time!
        but I will work on the time as you guide me ,thanks again 😉

  • Qai Jong

    Excellent article. Did you get to implement this? I am looking to implement the same for my project, if you could also share your implementation/code, it will be really helpful.

  • preeti


    I found this Article related to my project.Can anyone share a complete code for QR code localization.It will be a great help for me.My email id is preethychowdary@gmail.com

    Thanks in Advance.

  • Chris

    How are you doin the transformation with three points and getting the whole qr code? shouldnt u need all 4 points of the corners?

  • Anonyous

    Hi, a question for a million:
    have u tried to split ur code (github link given before) on .h and .cpp file? I got some problems making a class from ur code , something I cant get yet, like how goes custing from v<v<v>> to v when u use sort on vecpair[i].begin/end and why it doesnt work during class implementation…

    • Anonyous

      got an answer for my question, dont know yet if it works, but it compiled:
      so, just set compareContourAreas static and calling it like class:compareContourAreas.

  • Mojtaba Tabatabaie

    Hi, great article.
    Is this possible to share the code for this tutorial?
    I didn’t really get the second step after finding the contours.

  • Peen

    hi, this helps me a lot,tq:)
    may i know where is the part 2 of this tutorial?
    cause ive been searching for it but i didnt found it.