Camera preview hangs
dabcmexpertise opened this issue · 2 comments
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?
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.
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