{"action":"created","issue":{"url":"https://api.github.com/repos/opencv/opencv/issues/10081","repository_url":"https://api.github.com/repos/opencv/opencv","labels_url":"https://api.github.com/repos/opencv/opencv/issues/10081/labels{/name}","comments_url":"https://api.github.com/repos/opencv/opencv/issues/10081/comments","events_url":"https://api.github.com/repos/opencv/opencv/issues/10081/events","html_url":"https://github.com/opencv/opencv/pull/10081","id":273405639,"node_id":"MDExOlB1bGxSZXF1ZXN0MTUyMjIwMjAz","number":10081,"title":"[RFC] Java Camera2 View for Android","user":{"login":"floe","id":90756,"node_id":"MDQ6VXNlcjkwNzU2","avatar_url":"https://avatars0.githubusercontent.com/u/90756?v=4","gravatar_id":"","url":"https://api.github.com/users/floe","html_url":"https://github.com/floe","followers_url":"https://api.github.com/users/floe/followers","following_url":"https://api.github.com/users/floe/following{/other_user}","gists_url":"https://api.github.com/users/floe/gists{/gist_id}","starred_url":"https://api.github.com/users/floe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floe/subscriptions","organizations_url":"https://api.github.com/users/floe/orgs","repos_url":"https://api.github.com/users/floe/repos","events_url":"https://api.github.com/users/floe/events{/privacy}","received_events_url":"https://api.github.com/users/floe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"alalek","id":4981219,"node_id":"MDQ6VXNlcjQ5ODEyMTk=","avatar_url":"https://avatars0.githubusercontent.com/u/4981219?v=4","gravatar_id":"","url":"https://api.github.com/users/alalek","html_url":"https://github.com/alalek","followers_url":"https://api.github.com/users/alalek/followers","following_url":"https://api.github.com/users/alalek/following{/other_user}","gists_url":"https://api.github.com/users/alalek/gists{/gist_id}","starred_url":"https://api.github.com/users/alalek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alalek/subscriptions","organizations_url":"https://api.github.com/users/alalek/orgs","repos_url":"https://api.github.com/users/alalek/repos","events_url":"https://api.github.com/users/alalek/events{/privacy}","received_events_url":"https://api.github.com/users/alalek/received_events","type":"User","site_admin":false},"assignees":[{"login":"alalek","id":4981219,"node_id":"MDQ6VXNlcjQ5ODEyMTk=","avatar_url":"https://avatars0.githubusercontent.com/u/4981219?v=4","gravatar_id":"","url":"https://api.github.com/users/alalek","html_url":"https://github.com/alalek","followers_url":"https://api.github.com/users/alalek/followers","following_url":"https://api.github.com/users/alalek/following{/other_user}","gists_url":"https://api.github.com/users/alalek/gists{/gist_id}","starred_url":"https://api.github.com/users/alalek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alalek/subscriptions","organizations_url":"https://api.github.com/users/alalek/orgs","repos_url":"https://api.github.com/users/alalek/repos","events_url":"https://api.github.com/users/alalek/events{/privacy}","received_events_url":"https://api.github.com/users/alalek/received_events","type":"User","site_admin":false}],"milestone":null,"comments":22,"created_at":"2017-11-13T12:01:39Z","updated_at":"2019-01-05T01:34:55Z","closed_at":"2018-02-17T12:01:25Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/opencv/opencv/pulls/10081","html_url":"https://github.com/opencv/opencv/pull/10081","diff_url":"https://github.com/opencv/opencv/pull/10081.diff","patch_url":"https://github.com/opencv/opencv/pull/10081.patch"},"body":"Based on #10050, here's a first alpha implementation of the Camera2 adapter class which should allow zero-copy access to preview image data. Comments very welcome.\r\n\r\nKnown issues at the moment:\r\n\r\n- ~~tutorial2-mixedprocessing works with this class as a drop-in replacement for `JavaCameraView`, but quits after ~ 20-30 seconds (no crash, just exit due to internal camera queue error, perhaps some race condition?)~~ - fixed, was a memory leak\r\n- lots of code overlap with `JavaCameraView` and `Camera2Renderer` (e.g. `JavaCameraFrame` internal class), needs cleanup/refactoring\r\n- `cacPreviewSize(...)` currently buggy, selects smaller preview size than feasible\r\n\r\n```\r\nforce_builders=Android pack\r\n```"},"comment":{"url":"https://api.github.com/repos/opencv/opencv/issues/comments/451616276","html_url":"https://github.com/opencv/opencv/pull/10081#issuecomment-451616276","issue_url":"https://api.github.com/repos/opencv/opencv/issues/10081","id":451616276,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTYxNjI3Ng==","user":{"login":"ValkA","id":7328558,"node_id":"MDQ6VXNlcjczMjg1NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/7328558?v=4","gravatar_id":"","url":"https://api.github.com/users/ValkA","html_url":"https://github.com/ValkA","followers_url":"https://api.github.com/users/ValkA/followers","following_url":"https://api.github.com/users/ValkA/following{/other_user}","gists_url":"https://api.github.com/users/ValkA/gists{/gist_id}","starred_url":"https://api.github.com/users/ValkA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ValkA/subscriptions","organizations_url":"https://api.github.com/users/ValkA/orgs","repos_url":"https://api.github.com/users/ValkA/repos","events_url":"https://api.github.com/users/ValkA/events{/privacy}","received_events_url":"https://api.github.com/users/ValkA/received_events","type":"User","site_admin":false},"created_at":"2019-01-05T01:34:55Z","updated_at":"2019-01-05T01:34:55Z","author_association":"NONE","body":"To fix color conversion bugs (which I had in various devices/emulators) I would propose to do the following \r\n\r\nin JavaCamera2View I would change JavaCamera2Frame to:\r\n\r\n```\r\n    private class JavaCamera2Frame implements CvCameraViewFrame {\r\n        @Override\r\n        public Mat gray() {\r\n            return new Mat(mImage.getHeight(), mImage.getWidth(), CvType.CV_8UC1, mImage.getPlanes()[0].getBuffer());\r\n        }\r\n\r\n        @Override\r\n        public Mat rgba() {\r\n            Mat yuv420 = new Mat((3*mImage.getHeight())/2, mImage.getWidth(), CvType.CV_8UC1, mImage.getPlanes()[0].getBuffer());\r\n            switch (mImage.getFormat()){\r\n                case ImageFormat.YV12:\r\n                    Imgproc.cvtColor(yuv420, mRgba, Imgproc.COLOR_YUV2RGBA_YV12, 4);\r\n                    break;\r\n                case ImageFormat.NV21:\r\n                    Imgproc.cvtColor(yuv420, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4);\r\n                    break;\r\n                case ImageFormat.YUV_420_888:\r\n                    Imgproc.cvtColor(yuv420, mRgba, Imgproc.COLOR_YUV2RGBA_I420, 4);\r\n                    break;\r\n                default:\r\n                    throw new IllegalArgumentException(\"Preview Format can be NV21 or YV12\");\r\n            }\r\n\r\n            return mRgba;\r\n        }\r\n\r\n        public JavaCamera2Frame(Image image) {\r\n            super();\r\n            mImage = image;\r\n            mRgba = new Mat();\r\n        }\r\n\r\n        public void release() {\r\n            mRgba.release();\r\n        }\r\n\r\n        private Mat mRgba;\r\n        private Image mImage;\r\n    };\r\n```\r\n\r\nand OnImageAvailableListener to:\r\n```\r\nmImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {\r\n                @Override\r\n                public void onImageAvailable(ImageReader reader) {\r\n                    long t0 = System.currentTimeMillis();\r\n\r\n                    Image image = reader.acquireLatestImage();\r\n                    if (image == null)\r\n                        return;\r\n\r\n                    JavaCamera2Frame tempFrame = new JavaCamera2Frame(image);\r\n                    deliverAndDrawFrame(tempFrame);\r\n                    tempFrame.release();\r\n                    image.close();\r\n\r\n                    long t1 = System.currentTimeMillis();\r\n                    Log.d(LOGTAG, \"\" + 1000/(t1-t0) + \"fps\");\r\n                }\r\n            }, mBackgroundHandler);\r\n```"}}
{"actor":{"display_login":"ValkA"}}