Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding reding area limit #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

primissus
Copy link

Well, when I solved the issue https://github.com/nisrulz/qreader/issues/29 I made some changed that I cosidered not an optimal implementation of this tool, so I decided trying to improved what I did in that issue.
The first change is that I added a new class called QRBarcodeListener and I used it within the receiveDetections() method instead of QRDataListener and also changed the onDetected method of the QRDataListener class so you can add a Rect class to limit the reading area in order to receive data only if it is inside the bounds of that area. I also added another Rect that shows the area where the barcode has been detected so you can use those properties for some specific impletation.

Here is an example of these properties usage:

        final QRDataListener qrDataListener = new QRDataListener() {
            @Override
            public void onDetected(final String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        qReader.stop();
                        //The area of the read data
                        Rect readData = qrDataListener.getReadData();
                       ...
            }
        };
        //The area where data is going to be read
        qrDataListener.setReadingArea(areaRect);
        qReader = new QREader.Builder(ScanActivity.this, scanner, qrDataListener).facing(QREader.BACK_CAM)
                .enableAutofocus(true)
                .height(width)
                .width(height)
                .build();

@nisrulz
Copy link
Owner

nisrulz commented Nov 4, 2017

@primissus I just checked out your PR and doesn't seem to do what you proposed with the PR. I feel like I am missing something. Could you explain me a bit more about your PR?

@nisrulz
Copy link
Owner

nisrulz commented Mar 1, 2018

Hi @primissus any update on this?
Also you PR doesnot target develop. Please check that

@primissus primissus changed the base branch from master to develop March 22, 2018 04:39
@primissus
Copy link
Author

Hi @nisrulz , I'm sorry I forgot this PR.
Basically I changed the QRDataListener for a QRBarcodeListener in the QReader class in order to be able to detect the area where the QR code is detected, and even set the valid area to detect QR codes. This is because I needed to restrict the QR detection for one specific area.

If you want to know the area where the QR is detected you can use the getReadData() method from a QRDataListener like this:

Rect readDataArea = qrDataListener.getReadData();

And that method returns a Rect object that indicates the area where the QR code was detected so you can add more logic.
The complete example would be:

final QRDataListener qrDataListener = new QRDataListener() {
            @Override
            public void onDetected(final String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        qReader.stop();
                        //The area of the read data
                        Rect readDataArea = qrDataListener.getReadData();
                       ...
            }
        };

Maybe I committed a mistake declaring the getReadData() method and I should've declare it as getReadArea() instead.

But on the other hand, if you want to directly restrict the area for the QR detection you can use the setReadingArea(Rect area) method of your QRDataListener object so the onDetected() method will be called only if the QR code was detected within the area that you specified.
Like this:

Rect area = new Rect(...);
qrDataListener.setReadingArea(area);

@nisrulz
Copy link
Owner

nisrulz commented Oct 22, 2021

I never got back to this, but @primissus this is a good explanation of what was expected. I will see if it still holds true for the updated library code which is now in develop branch and uses Firebase Vision Library.

Thank you for detailed info and this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants