Actually FPS is very sensitive to a light conditions and it can variate in wide range (8-30 in my tests). I don't know any reliable way to increase FPS of preview, but only recomendations like decrease resolution, use native API and so on. I can suggest to use this lib https://github.com/natario1/CameraView - it provide the same FPS as native API, but significantly reduces volume of code.
Here is an example(Kotlin) to get RGB bitmap:
cameraView.addFrameProcessor { frame ->
if(frame!=null) {
val data = frame.data
val size = frame.size
// Process...
// cameraView.previewSize
val yuvImage = YuvImage(data, ImageFormat.NV21, size.width, size.height, null)
val os = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, size.width, size.height), 100, os)
val jpegByteArray = os.toByteArray()
var bitmap = BitmapFactory.decodeByteArray(jpegByteArray, 0, jpegByteArray.size)
}
}
And with openCV you can convert it to HSV very fast:
val bmp = convert(bitmap, Bitmap.Config.ARGB_8888)
var mat = Mat(bmp.width, bmp.height, CvType.CV_8UC4)
Utils.bitmapToMat(bmp, mat)
Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2HSV)
fun convert(bitmap: Bitmap, config: Bitmap.Config): Bitmap {
val convertedBitmap = Bitmap.createBitmap(bitmap.width, bitmap.height, config)
val canvas = Canvas(convertedBitmap)
val paint = Paint()
paint.color = Color.BLACK
canvas.drawBitmap(bitmap, 0F, 0F, paint)
return convertedBitmap
}