diff --git a/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown b/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown index 912b6d6c63..e8db73286b 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.markdown @@ -62,8 +62,8 @@ We need **CMake** to configure the installation, **GCC** for compilation, **Pyth ``` sudo apt-get install cmake -sudo apt-get install python-devel numpy -sudo apt-get install gcc gcc-c++ +sudo apt-get install python-dev python-numpy +sudo apt-get install gcc g++ ``` Next we need **GTK** support for GUI features, Camera support (v4l), Media Support diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 5945e8db11..eb82003d0a 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -546,6 +546,43 @@ void ONNXImporter::populateNet(Net dstNet) { replaceLayerParam(layerParams, "size", "local_size"); } + else if (layer_type == "InstanceNormalization") + { + if (node_proto.input_size() != 3) + CV_Error(Error::StsNotImplemented, + "Expected input, scale, bias"); + + layerParams.blobs.resize(4); + layerParams.blobs[2] = getBlob(node_proto, constBlobs, 1); // weightData + layerParams.blobs[3] = getBlob(node_proto, constBlobs, 2); // biasData + layerParams.set("has_bias", true); + layerParams.set("has_weight", true); + + // Get number of channels in input + int size = layerParams.blobs[2].total(); + layerParams.blobs[0] = Mat::zeros(size, 1, CV_32F); // mean + layerParams.blobs[1] = Mat::ones(size, 1, CV_32F); // std + + LayerParams mvnParams; + mvnParams.name = layerParams.name + "/MVN"; + mvnParams.type = "MVN"; + mvnParams.set("eps", layerParams.get("epsilon")); + layerParams.erase("epsilon"); + + //Create MVN layer + int id = dstNet.addLayer(mvnParams.name, mvnParams.type, mvnParams); + //Connect to input + layerId = layer_id.find(node_proto.input(0)); + CV_Assert(layerId != layer_id.end()); + dstNet.connect(layerId->second.layerId, layerId->second.outputId, id, 0); + //Add shape + layer_id.insert(std::make_pair(mvnParams.name, LayerInfo(id, 0))); + outShapes[mvnParams.name] = outShapes[node_proto.input(0)]; + + //Replace Batch Norm's input to MVN + node_proto.set_input(0, mvnParams.name); + layerParams.type = "BatchNorm"; + } else if (layer_type == "BatchNormalization") { if (node_proto.input_size() != 5) diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 186239494f..fc38a2378c 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -76,6 +76,14 @@ public: } }; +TEST_P(Test_ONNX_layers, InstanceNorm) +{ + if (target == DNN_TARGET_MYRIAD) + testONNXModels("instancenorm", npy, 0, 0, false, false); + else + testONNXModels("instancenorm", npy); +} + TEST_P(Test_ONNX_layers, MaxPooling) { testONNXModels("maxpooling"); diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index c807612458..847dda144a 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -723,21 +723,25 @@ bool imwrite( const String& filename, InputArray _img, static bool imdecode_( const Mat& buf, int flags, Mat& mat ) { - CV_Assert(!buf.empty() && buf.isContinuous()); + CV_Assert(!buf.empty()); + CV_Assert(buf.isContinuous()); + CV_Assert(buf.checkVector(1, CV_8U) > 0); + Mat buf_row = buf.reshape(1, 1); // decoders expects single row, avoid issues with vector columns + String filename; - ImageDecoder decoder = findDecoder(buf); + ImageDecoder decoder = findDecoder(buf_row); if( !decoder ) return 0; - if( !decoder->setSource(buf) ) + if( !decoder->setSource(buf_row) ) { filename = tempfile(); FILE* f = fopen( filename.c_str(), "wb" ); if( !f ) return 0; - size_t bufSize = buf.cols*buf.rows*buf.elemSize(); - if( fwrite( buf.ptr(), 1, bufSize, f ) != bufSize ) + size_t bufSize = buf_row.total()*buf.elemSize(); + if (fwrite(buf_row.ptr(), 1, bufSize, f) != bufSize) { fclose( f ); CV_Error( Error::StsError, "failed to write image data to temporary file" ); diff --git a/modules/imgproc/test/ocl/test_color.cpp b/modules/imgproc/test/ocl/test_color.cpp index 0d08de0753..bdbc6a90d0 100644 --- a/modules/imgproc/test/ocl/test_color.cpp +++ b/modules/imgproc/test/ocl/test_color.cpp @@ -294,14 +294,14 @@ OCL_TEST_P(CvtColor8u, GRAY2BGR555) { performTest(1, 2, CVTCODE(GRAY2BGR555)); } // RGBA <-> mRGBA -#ifdef HAVE_IPP +#if defined(HAVE_IPP) || defined(__arm__) #define IPP_EPS depth <= CV_32S ? 1 : 1e-3 #else #define IPP_EPS 1e-3 #endif OCL_TEST_P(CvtColor8u, RGBA2mRGBA) { performTest(4, 4, CVTCODE(RGBA2mRGBA), IPP_EPS); } -OCL_TEST_P(CvtColor8u, mRGBA2RGBA) { performTest(4, 4, CVTCODE(mRGBA2RGBA)); } +OCL_TEST_P(CvtColor8u, mRGBA2RGBA) { performTest(4, 4, CVTCODE(mRGBA2RGBA), IPP_EPS); } // RGB <-> Lab diff --git a/modules/java/generator/android-21/java/org/opencv/android/JavaCamera2View.java b/modules/java/generator/android-21/java/org/opencv/android/JavaCamera2View.java index c22eaa90d5..e4a58539b5 100644 --- a/modules/java/generator/android-21/java/org/opencv/android/JavaCamera2View.java +++ b/modules/java/generator/android-21/java/org/opencv/android/JavaCamera2View.java @@ -2,6 +2,7 @@ package org.opencv.android; import java.nio.ByteBuffer; import java.util.Arrays; +import java.util.List; import android.annotation.TargetApi; import android.content.Context; @@ -24,6 +25,7 @@ import android.view.ViewGroup.LayoutParams; import org.opencv.core.CvType; import org.opencv.core.Mat; +import org.opencv.core.Size; import org.opencv.imgproc.Imgproc; /** @@ -248,6 +250,20 @@ public class JavaCamera2View extends CameraBridgeViewBase { } } + public static class JavaCameraSizeAccessor implements ListItemAccessor { + @Override + public int getWidth(Object obj) { + android.util.Size size = (android.util.Size)obj; + return size.getWidth(); + } + + @Override + public int getHeight(Object obj) { + android.util.Size size = (android.util.Size)obj; + return size.getHeight(); + } + } + boolean calcPreviewSize(final int width, final int height) { Log.i(LOGTAG, "calcPreviewSize: " + width + "x" + height); if (mCameraID == null) { @@ -258,26 +274,15 @@ public class JavaCamera2View extends CameraBridgeViewBase { try { CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraID); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); - int bestWidth = 0, bestHeight = 0; - float aspect = (float) width / height; android.util.Size[] sizes = map.getOutputSizes(ImageReader.class); - bestWidth = sizes[0].getWidth(); - bestHeight = sizes[0].getHeight(); - for (android.util.Size sz : sizes) { - int w = sz.getWidth(), h = sz.getHeight(); - Log.d(LOGTAG, "trying size: " + w + "x" + h); - if (width >= w && height >= h && bestWidth <= w && bestHeight <= h - && Math.abs(aspect - (float) w / h) < 0.2) { - bestWidth = w; - bestHeight = h; - } - } - Log.i(LOGTAG, "best size: " + bestWidth + "x" + bestHeight); - assert(!(bestWidth == 0 || bestHeight == 0)); - if (mPreviewSize.getWidth() == bestWidth && mPreviewSize.getHeight() == bestHeight) + List sizes_list = Arrays.asList(sizes); + Size frameSize = calculateCameraFrameSize(sizes_list, new JavaCameraSizeAccessor(), width, height); + Log.i(LOGTAG, "Selected preview size to " + Integer.valueOf((int)frameSize.width) + "x" + Integer.valueOf((int)frameSize.height)); + assert(!(frameSize.width == 0 || frameSize.height == 0)); + if (mPreviewSize.getWidth() == frameSize.width && mPreviewSize.getHeight() == frameSize.height) return false; else { - mPreviewSize = new android.util.Size(bestWidth, bestHeight); + mPreviewSize = new android.util.Size((int)frameSize.width, (int)frameSize.height); return true; } } catch (CameraAccessException e) { diff --git a/modules/java/generator/android/java/org/opencv/android/CameraBridgeViewBase.java b/modules/java/generator/android/java/org/opencv/android/CameraBridgeViewBase.java index 54871057e2..681b7ab974 100644 --- a/modules/java/generator/android/java/org/opencv/android/CameraBridgeViewBase.java +++ b/modules/java/generator/android/java/org/opencv/android/CameraBridgeViewBase.java @@ -30,7 +30,7 @@ import android.view.SurfaceView; public abstract class CameraBridgeViewBase extends SurfaceView implements SurfaceHolder.Callback { private static final String TAG = "CameraBridge"; - private static final int MAX_UNSPECIFIED = -1; + protected static final int MAX_UNSPECIFIED = -1; private static final int STOPPED = 0; private static final int STARTED = 1; @@ -481,6 +481,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac for (Object size : supportedSizes) { int width = accessor.getWidth(size); int height = accessor.getHeight(size); + Log.d(TAG, "trying size: " + width + "x" + height); if (width <= maxAllowedWidth && height <= maxAllowedHeight) { if (width >= calcWidth && height >= calcHeight) { @@ -489,6 +490,13 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac } } } + if ((calcWidth == 0 || calcHeight == 0) && supportedSizes.size() > 0) + { + Log.i(TAG, "fallback to the first frame size"); + Object size = supportedSizes.get(0); + calcWidth = accessor.getWidth(size); + calcHeight = accessor.getHeight(size); + } return new Size(calcWidth, calcHeight); } diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 943cc6ee7b..948ba0d576 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -500,7 +500,8 @@ bool CvCaptureCAM_V4L::autosetup_capture_mode_v4l2() V4L2_PIX_FMT_JPEG, #endif V4L2_PIX_FMT_Y16, - V4L2_PIX_FMT_GREY + V4L2_PIX_FMT_Y10, + V4L2_PIX_FMT_GREY, }; for (size_t i = 0; i < sizeof(try_order) / sizeof(__u32); i++) { @@ -547,6 +548,7 @@ bool CvCaptureCAM_V4L::convertableToRgb() const case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_Y16: + case V4L2_PIX_FMT_Y10: case V4L2_PIX_FMT_GREY: case V4L2_PIX_FMT_BGR24: return true; @@ -581,6 +583,7 @@ void CvCaptureCAM_V4L::v4l2_create_frame() size.height = size.height * 3 / 2; // "1.5" channels break; case V4L2_PIX_FMT_Y16: + case V4L2_PIX_FMT_Y10: depth = IPL_DEPTH_16U; /* fallthru */ case V4L2_PIX_FMT_GREY: @@ -1455,6 +1458,13 @@ void CvCaptureCAM_V4L::convertToRgb(const Buffer ¤tBuffer) cv::cvtColor(temp, destination, COLOR_GRAY2BGR); return; } + case V4L2_PIX_FMT_Y10: + { + cv::Mat temp(imageSize, CV_8UC1, buffers[MAX_V4L_BUFFERS].start); + cv::Mat(imageSize, CV_16UC1, currentBuffer.start).convertTo(temp, CV_8U, 1.0 / 4); + cv::cvtColor(temp, destination, COLOR_GRAY2BGR); + return; + } case V4L2_PIX_FMT_GREY: cv::cvtColor(cv::Mat(imageSize, CV_8UC1, currentBuffer.start), destination, COLOR_GRAY2BGR); break;