Adding reding area limit
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();
@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?
Hi @primissus any update on this?
Also you PR doesnot target develop. Please check that
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);
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.