Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin 2021-07-10 13:01:03 +00:00
commit 9e42e04b4a
5 changed files with 18 additions and 14 deletions

View File

@ -925,7 +925,7 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
int blob_total = blob.total(); int blob_total = blob.total();
if (blob_total == 1) { if (blob_total == 1) {
layerParams.type = "Power"; layerParams.type = "Power";
layerParams.set("shift", (isSub ? -1 : 1) * blob.at<float>(0)); layerParams.set("shift", (isSub ? -1 : 1) * blob.ptr<float>()[0]);
} }
else { else {
MatShape inpShape = outShapes[node_proto.input(1 - const_blob_id)]; MatShape inpShape = outShapes[node_proto.input(1 - const_blob_id)];
@ -1019,7 +1019,7 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
blob.convertTo(blob, CV_32F); blob.convertTo(blob, CV_32F);
layerParams.type = "Power"; layerParams.type = "Power";
layerParams.set("power", blob.at<float>(0)); layerParams.set("power", blob.ptr<float>()[0]);
} }
else if (layer_type == "Max") else if (layer_type == "Max")
{ {
@ -1305,7 +1305,8 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
Mat blob = getBlob(node_proto, constId); Mat blob = getBlob(node_proto, constId);
blob = blob.reshape(1, 1); blob = blob.reshape(1, 1);
if (blob.total() == 1) { if (blob.total() == 1) {
float coeff = isDiv ? 1.0 / blob.at<float>(0) : blob.at<float>(0); float blob_value = blob.ptr<float>()[0];
float coeff = isDiv ? 1.0 / blob_value : blob_value;
layerParams.set("scale", coeff); layerParams.set("scale", coeff);
layerParams.type = "Power"; layerParams.type = "Power";
} }
@ -1343,12 +1344,14 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
{ {
if (inp0.total() == 1) if (inp0.total() == 1)
{ {
float coeff = isDiv ? 1.0 / inp0.at<float>(0) : inp0.at<float>(0); float inp0_value = inp0.ptr<float>()[0];
float coeff = isDiv ? 1.0 / inp0_value : inp0_value;
multiply(inp1, coeff, out); multiply(inp1, coeff, out);
} }
else else
{ {
float coeff = isDiv ? 1.0 / inp1.at<float>(0) : inp1.at<float>(0); float inp1_value = inp1.ptr<float>()[0];
float coeff = isDiv ? 1.0 / inp1_value : inp1_value;
multiply(inp0, coeff, out); multiply(inp0, coeff, out);
} }
@ -1767,7 +1770,7 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
if (node_proto.input_size() == 3) if (node_proto.input_size() == 3)
{ {
Mat value = getBlob(node_proto, 2); Mat value = getBlob(node_proto, 2);
layerParams.set("value", value.at<float>(0)); layerParams.set("value", value.ptr<float>()[0]);
} }
} }
} }

View File

@ -2883,18 +2883,19 @@ inline bool DefaultViewPort::isSameSize(IplImage* img1, IplImage* img2)
void DefaultViewPort::controlImagePosition() void DefaultViewPort::controlImagePosition()
{ {
qreal left, top, right, bottom; qreal left, top, right, bottom;
qreal factor = 1.0 / param_matrixWorld.m11();
//after check top-left, bottom right corner to avoid getting "out" during zoom/panning //after check top-left, bottom right corner to avoid getting "out" during zoom/panning
param_matrixWorld.map(0,0,&left,&top); param_matrixWorld.map(0,0,&left,&top);
if (left > 0) if (left > 0)
{ {
param_matrixWorld.translate(-left,0); param_matrixWorld.translate(-left * factor, 0);
left = 0; left = 0;
} }
if (top > 0) if (top > 0)
{ {
param_matrixWorld.translate(0,-top); param_matrixWorld.translate(0, -top * factor);
top = 0; top = 0;
} }
//------- //-------
@ -2903,12 +2904,12 @@ void DefaultViewPort::controlImagePosition()
param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom); param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
if (right < sizeImage.width()) if (right < sizeImage.width())
{ {
param_matrixWorld.translate(sizeImage.width()-right,0); param_matrixWorld.translate((sizeImage.width() - right) * factor, 0);
right = sizeImage.width(); right = sizeImage.width();
} }
if (bottom < sizeImage.height()) if (bottom < sizeImage.height())
{ {
param_matrixWorld.translate(0,sizeImage.height()-bottom); param_matrixWorld.translate(0, (sizeImage.height() - bottom) * factor);
bottom = sizeImage.height(); bottom = sizeImage.height();
} }

View File

@ -124,6 +124,7 @@ struct RiffList
uint32_t m_size; uint32_t m_size;
uint32_t m_list_type_cc; uint32_t m_list_type_cc;
}; };
#pragma pack(pop)
class VideoInputStream class VideoInputStream
{ {
@ -149,7 +150,6 @@ private:
String m_fname; String m_fname;
}; };
#pragma pack(pop)
inline VideoInputStream& operator >> (VideoInputStream& is, AviMainHeader& avih) inline VideoInputStream& operator >> (VideoInputStream& is, AviMainHeader& avih)
{ {

View File

@ -50,7 +50,7 @@ int main(int argc, char **argv)
" https://github.com/richzhang/colorization\n" " https://github.com/richzhang/colorization\n"
"Download caffemodel and prototxt files:\n" "Download caffemodel and prototxt files:\n"
" http://eecs.berkeley.edu/~rich.zhang/projects/2016_colorization/files/demo_v2/colorization_release_v2.caffemodel\n" " http://eecs.berkeley.edu/~rich.zhang/projects/2016_colorization/files/demo_v2/colorization_release_v2.caffemodel\n"
" https://raw.githubusercontent.com/richzhang/colorization/master/colorization/models/colorization_deploy_v2.prototxt\n"; " https://raw.githubusercontent.com/richzhang/colorization/caffe/models/colorization_deploy_v2.prototxt\n";
const string keys = const string keys =
"{ h help | | print this help message }" "{ h help | | print this help message }"
"{ proto | colorization_deploy_v2.prototxt | model configuration }" "{ proto | colorization_deploy_v2.prototxt | model configuration }"

View File

@ -1,6 +1,6 @@
# Script is based on https://github.com/richzhang/colorization/blob/master/colorization/colorize.py # Script is based on https://github.com/richzhang/colorization/blob/master/colorization/colorize.py
# To download the caffemodel and the prototxt, see: https://github.com/richzhang/colorization/tree/master/colorization/models # To download the caffemodel and the prototxt, see: https://github.com/richzhang/colorization/tree/caffe/colorization/models
# To download pts_in_hull.npy, see: https://github.com/richzhang/colorization/blob/master/colorization/resources/pts_in_hull.npy # To download pts_in_hull.npy, see: https://github.com/richzhang/colorization/tree/caffe/colorization/resources/pts_in_hull.npy
import numpy as np import numpy as np
import argparse import argparse
import cv2 as cv import cv2 as cv