二个是添加layerModelBlending函数实体。
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
#include "opencv2/photo.hpp"
using namespace std;
using namespace cv;
#define EPSILON 1e-6f
#define SAFE_DIV_MIN EPSILON
#define SAFE_DIV_MAX (1.0f / SAFE_DIV_MIN)
#define CLAMP(f,min,max) ((f)<(min)?(min):(f)>(max)?(max):(f))
namespace cv
{
/* local function prototypes */
static inline float safe_div(float a, float b);
/* returns a / b, clamped to [-SAFE_DIV_MAX, SAFE_DIV_MAX].
* if -SAFE_DIV_MIN <= a <= SAFE_DIV_MIN, returns 0.
*/
static inline float safe_div(float a, float b)
{
float result = 0.0f;
if (fabsf(a) > SAFE_DIV_MIN)
{
result = a / b;
result = CLAMP(result, -SAFE_DIV_MAX, SAFE_DIV_MAX);
}
return result;
}
CV_EXPORTS_W void layerModelBlending(InputArray _target, InputArray _blend, OutputArray _dst, int flag)
{
Mat target = _target.getMat();
Mat blend = _blend.getMat();
Mat dst = _dst.getMat();
for (int index_row = 0; index_row < target.rows; index_row++)
for (int index_col = 0; index_col < target.cols; index_col++)
for (int index_c = 0; index_c < 3; index_c++)
switch (flag)
{
case DARKEN:
dst.at<Vec3f>(index_row, index_col)[index_c] = min(
target.at<Vec3f>(index_row, index_col)[index_c],
blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case MULTIPY:
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] *
blend.at<Vec3f>(index_row, index_col)[index_c];
break;
case COLOR_BURN:
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
safe_div((1 - target.at<Vec3f>(index_row, index_col)[index_c]),
blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case LINEAR_BRUN:
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] +
blend.at<Vec3f>(index_row, index_col)[index_c] - 1;
break;
case LIGHTEN:
dst.at<Vec3f>(index_row, index_col)[index_c] = max(
target.at<Vec3f>(index_row, index_col)[index_c],
blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case SCREEN:
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
(1 - target.at<Vec3f>(index_row, index_col)[index_c]) *
(1 - blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case COLOR_DODGE:
dst.at<Vec3f>(index_row, index_col)[index_c] = safe_div
(target.at<Vec3f>(index_row, index_col)[index_c],
1 - blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case LINEAR_DODGE:
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] +
blend.at<Vec3f>(index_row, index_col)[index_c];
break;
case OVERLAY:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
(1 - 2 * (target.at<Vec3f>(index_row, index_col)[index_c] - 0.5)) *
(1 - blend.at<Vec3f>(index_row, index_col)[index_c]);
else
dst.at<Vec3f>(index_row, index_col)[index_c] = 2 *
target.at<Vec3f>(index_row, index_col)[index_c] *
blend.at<Vec3f>(index_row, index_col)[index_c];
break;
case SOFT_LIGHT:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
(1 - target.at<Vec3f>(index_row, index_col)[index_c]) *
(1 - (blend.at<Vec3f>(index_row, index_col)[index_c] - 0.5));
else
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] *
(blend.at<Vec3f>(index_row, index_col)[index_c] + 0.5);
break;
case HARD_LIGHT:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
(1 - target.at<Vec3f>(index_row, index_col)[index_c]) *
(1 - 2 * blend.at<Vec3f>(index_row, index_col)[index_c] - 0.5);
else
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] *
(2 * blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case VIVID_LIGHT:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] = 1 -
safe_div(1 - target.at<Vec3f>(index_row, index_col)[index_c],
(2 * (blend.at<Vec3f>(index_row, index_col)[index_c] - 0.5)));
else
dst.at<Vec3f>(index_row, index_col)[index_c] =
safe_div(target.at<Vec3f>(index_row, index_col)[index_c],
(1 - 2 * blend.at<Vec3f>(index_row, index_col)[index_c]));
break;
case LINEAR_LIGHT:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] +
(2 * (blend.at<Vec3f>(index_row, index_col)[index_c] - 0.5));
else
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] +
2 * blend.at<Vec3f>(index_row, index_col)[index_c] - 1;
break;
case PIN_LIGHT:
if (target.at<Vec3f>(index_row, index_col)[index_c] > 0.5f)
dst.at<Vec3f>(index_row, index_col)[index_c] =
max(target.at<Vec3f>(index_row, index_col)[index_c],
(float)(2 * (blend.at<Vec3f>(index_row, index_col)[index_c] - 0.5)));
else
dst.at<Vec3f>(index_row, index_col)[index_c] =
min(target.at<Vec3f>(index_row, index_col)[index_c],
2 * blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case DIFFERENCE:
dst.at<Vec3f>(index_row, index_col)[index_c] =
abs(target.at<Vec3f>(index_row, index_col)[index_c] -
blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
case EXCLUSION:
dst.at<Vec3f>(index_row, index_col)[index_c] =
target.at<Vec3f>(index_row, index_col)[index_c] +
blend.at<Vec3f>(index_row, index_col)[index_c] -
2 * target.at<Vec3f>(index_row, index_col)[index_c] * blend.at<Vec3f>(index_row, index_col)[index_c];
break;
case DIVIDE:
dst.at<Vec3f>(index_row, index_col)[index_c] =
safe_div(target.at<Vec3f>(index_row, index_col)[index_c],
blend.at<Vec3f>(index_row, index_col)[index_c]);
break;
}
}
}
由于有seamlessclone可以参考,所以这里很多东西,虽然繁琐、但是并不是没有解决方法。直到我发现在都设置正确的情况,总是出现link错误。我知道link错误是由于dll文件问题。经过研究发现:那么是缺少cv,添加之后。 0000C793 1896 0767 ?layerModelBlending@@YAXVMat@cv@@00H@Z
0000AEF7 2297 08F8 ?seamlessClone@cv@@YAXAEBV_InputArray@debug_build_guard@1@00V?
你发现,我们缺少CV,通过添加namespcae、能够变成这样 0000A209 1896 0767 ?layerModelBlending@cv@@YAXVMat@1@00H@Z
再发现问题,通过修改形参,便成为:layerModelBlending@cv@@YAXAEBV_InputArray@debug_build_guard@1@0AEBV_OutputArray@31@H@Z
调用成功。三、反思小结我在问题出现的地方卡了2天时间,直到去尝试寻找"dll文件结构查看器",才能够定位问题。使用"dll文件结构查看器"的能力我之前是不具备的,今后是会经常使用的。但是关键在于矛盾之中的思考,也就是处于矛盾情况下,不能一味地重复劳动,而是要跳出圈子,思考根本问题。这才是我记录本BLOG的关键。来自为知笔记(Wiz)