Skip to content

Commit 6a8f57e

Browse files
floealalek
authored andcommitted
Merge pull request opencv#10081 from floe:java-camera2-view
* add (untested) JavaCamera2View class * initial fixes * minor cleanup * exclude JavaCamera2View from build for older SDK version * fix method name typo * add asserts + sanity checks * fix preview format checks * fix the memory leak * export cvtTwoPlaneYUVtoBGR for Java usage * add handling for two-plane YUV frames (C wrapper still missing) * add two-plane cvtColor helper function * fix warnings * actually use the new cvtColorTwoPlane helper func * fix wrong output matrix size * fix wrong conversion type * simplify method signature, add error condition * minor fixes to Mat types * remove leftover semaphore from camera api 1 * android: JavaCamera2View minor refactoring - re-apply Java code style - imports cleanup - dump exceptions information * android: JavaCamera2View: pause/resume fixes * android: JavaCamera2View: fix mScale
1 parent eb94dfb commit 6a8f57e

File tree

3 files changed

+412
-0
lines changed

3 files changed

+412
-0
lines changed

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,8 @@ channels is derived automatically from src and code.
36943694
*/
36953695
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
36963696

3697+
CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code );
3698+
36973699
//! @} imgproc_misc
36983700

36993701
// main function for all demosaicing processes

modules/imgproc/src/color.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11050,6 +11050,42 @@ inline bool isFullRange(int code)
1105011050

1105111051
} // namespace::
1105211052

11053+
// helper function for dual-plane modes
11054+
void cv::cvtColorTwoPlane( InputArray _ysrc, InputArray _uvsrc, OutputArray _dst, int code )
11055+
{
11056+
// only YUV420 is currently supported
11057+
switch (code) {
11058+
case COLOR_YUV2BGR_NV21: case COLOR_YUV2RGB_NV21: case COLOR_YUV2BGR_NV12: case COLOR_YUV2RGB_NV12:
11059+
case COLOR_YUV2BGRA_NV21: case COLOR_YUV2RGBA_NV21: case COLOR_YUV2BGRA_NV12: case COLOR_YUV2RGBA_NV12:
11060+
break;
11061+
default:
11062+
CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );
11063+
return;
11064+
}
11065+
11066+
int stype = _ysrc.type();
11067+
int depth = CV_MAT_DEPTH(stype), uidx, dcn;
11068+
11069+
Mat ysrc, uvsrc, dst;
11070+
ysrc = _ysrc.getMat();
11071+
uvsrc = _uvsrc.getMat();
11072+
Size ysz = _ysrc.size();
11073+
Size uvs = _uvsrc.size();
11074+
11075+
// http://www.fourcc.org/yuv.php#NV21 == yuv420sp -> a plane of 8 bit Y samples followed by an interleaved V/U plane containing 8 bit 2x2 subsampled chroma samples
11076+
// http://www.fourcc.org/yuv.php#NV12 -> a plane of 8 bit Y samples followed by an interleaved U/V plane containing 8 bit 2x2 subsampled colour difference samples
11077+
dcn = (code==COLOR_YUV420sp2BGRA || code==COLOR_YUV420sp2RGBA || code==COLOR_YUV2BGRA_NV12 || code==COLOR_YUV2RGBA_NV12) ? 4 : 3;
11078+
uidx = (code==COLOR_YUV2BGR_NV21 || code==COLOR_YUV2BGRA_NV21 || code==COLOR_YUV2RGB_NV21 || code==COLOR_YUV2RGBA_NV21) ? 1 : 0;
11079+
CV_Assert( dcn == 3 || dcn == 4 );
11080+
CV_Assert( ysz.width == uvs.width * 2 );
11081+
CV_Assert( ysz.width % 2 == 0 && depth == CV_8U );
11082+
CV_Assert( ysz.height == uvs.height * 2 );
11083+
_dst.create( ysz, CV_MAKETYPE(depth, dcn));
11084+
dst = _dst.getMat();
11085+
hal::cvtTwoPlaneYUVtoBGR(ysrc.data, uvsrc.data, ysrc.step, dst.data, dst.step, dst.cols, dst.rows, dcn, swapBlue(code), uidx);
11086+
}
11087+
11088+
1105311089
//////////////////////////////////////////////////////////////////////////////////////////
1105411090
// The main function //
1105511091
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)