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

Camera preview hangs #2

Open
dabcmexpertise opened this issue Mar 6, 2019 · 2 comments
Open

Camera preview hangs #2

dabcmexpertise opened this issue Mar 6, 2019 · 2 comments

Comments

@dabcmexpertise
Copy link

Hello,

Code is great but camera preview hangs. When investigated, I found that this code is causing problem

ScanCardFragment :

` @OverRide
public Mat onCameraFrame(CameraBridgeViewBase2.CvCameraViewFrame inputFrame) {
rgba = inputFrame.rgba();

    if (isScanning && dealRetriever.getDeal().getHand(currentPos).getCards().size() < 32)
    {
        Core.transform(rgba, gray, coefficients);

        /***This line is causing problem***/

        Imgproc.adaptiveThreshold(gray, bw, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 101, 35);

        /***This line is causing problem***/

        cards = detector.detectCardsInImage(bw, rgba);
        cards_set = CardDetector.CardsToSet(cards);
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                if(dealUpdater !=null && currentPos !=null && cards_set!=null){
                    dealUpdater.addCardsToHand(currentPos, cards_set);
                }


            }
        });
    }
    return rgba;
}`

Can you help me in Imgprov.adaptiveThreshold function?

@fvannee
Copy link
Owner

fvannee commented Mar 6, 2019

Hi, sorry it's been a while since I last saw this code.
The adaptiveThreshold function is supposed to transform the image in grey to a black/white image. This is quite difficult due to different possible lightnings in the image. From what I remember this part is not supposed to be very slow (the detecting of cards should be slower than converting it to black/white). Did you try some different parameters to the function to see if it made any difference? Or perhaps difference opencv implementations? I don't remember experiencing issues with it back then, but I'm well aware a lot has changed.

@dabcmexpertise
Copy link
Author

dabcmexpertise commented Mar 12, 2019

I updated to latest openCV implementation but problem seems same.

I am sure that this function is causing an issue because if I remove this function from code, CameraPreview works smoothly.

Imgproc.adaptiveThreshold(gray, bw, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 101, 35);

Here I tried to change with different parameters. like changing blocksize or last double parameter value but then It stops Identifying cards as desired.

I learned about this funcion from following link : https://www.tutorialspoint.com/opencv/opencv_adaptive_threshold.htm

But any change of parameter makes function useless

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

No branches or pull requests

2 participants