#include <iostream>
static float hull_pts[] = {
-90., -90., -90., -90., -90., -80., -80., -80., -80., -80., -80., -80., -80., -70., -70., -70., -70., -70., -70., -70., -70.,
-70., -70., -60., -60., -60., -60., -60., -60., -60., -60., -60., -60., -60., -60., -50., -50., -50., -50., -50., -50., -50., -50.,
-50., -50., -50., -50., -50., -50., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -40., -30.,
-30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -30., -20., -20., -20., -20., -20., -20., -20.,
-20., -20., -20., -20., -20., -20., -20., -20., -20., -10., -10., -10., -10., -10., -10., -10., -10., -10., -10., -10., -10., -10.,
-10., -10., -10., -10., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 10., 10., 10., 10., 10., 10., 10.,
10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
20., 20., 20., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 40., 40., 40., 40.,
40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 40., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50.,
50., 50., 50., 50., 50., 50., 50., 50., 50., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60., 60.,
60., 60., 60., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 70., 80., 80., 80.,
80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 80., 90., 90., 90., 90., 90., 90., 90., 90., 90., 90.,
90., 90., 90., 90., 90., 90., 90., 90., 90., 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 50., 60., 70., 80., 90.,
20., 30., 40., 50., 60., 70., 80., 90., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., -20., -10., 0., 10., 20., 30., 40., 50.,
60., 70., 80., 90., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., -40., -30., -20., -10., 0., 10., 20.,
30., 40., 50., 60., 70., 80., 90., 100., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., -50.,
-40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., -60., -50., -40., -30., -20., -10., 0., 10., 20.,
30., 40., 50., 60., 70., 80., 90., 100., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90.,
100., -80., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., -80., -70., -60., -50.,
-40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., -90., -80., -70., -60., -50., -40., -30., -20., -10.,
0., 10., 20., 30., 40., 50., 60., 70., 80., 90., -100., -90., -80., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30.,
40., 50., 60., 70., 80., 90., -100., -90., -80., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70.,
80., -110., -100., -90., -80., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., -110., -100.,
-90., -80., -70., -60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., 80., -110., -100., -90., -80., -70.,
-60., -50., -40., -30., -20., -10., 0., 10., 20., 30., 40., 50., 60., 70., -110., -100., -90., -80., -70., -60., -50., -40., -30.,
-20., -10., 0., 10., 20., 30., 40., 50., 60., 70., -90., -80., -70., -60., -50., -40., -30., -20., -10., 0.
};
int main(
int argc,
char **argv)
{
const string about =
"此示例演示如何使用 dnn 對灰度影像進行重新著色。\n"
"此程式基於:\n"
" http://richzhang.github.io/colorization\n"
" https://github.com/richzhang/colorization\n"
"下載 caffemodel 和 prototxt 檔案:\n"
" http://eecs.berkeley.edu/~rich.zhang/projects/2016_colorization/files/demo_v2/colorization_release_v2.caffemodel\n"
" https://raw.githubusercontent.com/richzhang/colorization/caffe/models/colorization_deploy_v2.prototxt\n";
const string keys =
"{ h help | | 列印此幫助訊息 }"
"{ proto | colorization_deploy_v2.prototxt | 模型配置 }"
"{ model | colorization_release_v2.caffemodel | 模型權重 }"
"{ image | space_shuttle.jpg | 影像檔案路徑 }"
"{ opencl | | 啟用 OpenCL }";
parser.about(about);
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
string modelTxt = samples::findFile(parser.get<string>("proto"));
string modelBin = samples::findFile(parser.get<string>("model"));
string imageFile = samples::findFile(parser.get<string>("image"));
if (!parser.check())
{
parser.printErrors();
return 1;
}
{
cout << "無法從檔案讀取影像:" << imageFile << endl;
return 2;
}
const int W_in = 224;
const int H_in = 224;
Net net = dnn::readNetFromCaffe(modelTxt, modelBin);
if (useOpenCL)
int sz[] = {2, 313, 1, 1};
const Mat pts_in_hull(4, sz,
CV_32F, hull_pts);
class8_ab->blobs.push_back(pts_in_hull);
input -= 50;
Mat color, chn[] = {L, a, b};
return 0;
}
如果陣列沒有元素,則返回 true。
int64_t int64
MatSize size
定義 mat.hpp:2187
uchar * ptr(int i0=0)
返回指向指定矩陣行的指標。
cv::getTickFrequency
double getTickFrequency()
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
使用可選縮放將陣列轉換為另一種資料型別。
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
此類允許建立和操作全面的大型神經網路。
定義 dnn.hpp:475
void setInput(CV_ND InputArray blob, const String &name="", double scalefactor=1.0, const Scalar &mean=Scalar())
設定網路的新輸入值。
Mat forward(const String &outputName=String())
執行前向傳遞以計算具有名稱 outputName 的層的輸出。
void setPreferableTarget(int targetId)
要求網路在特定目標裝置上進行計算。
Ptr< Layer > getLayer(int layerId) const
返回指向具有指定 id 或名稱的層的指標,該層由網路使用。
void merge(const Mat *mv, size_t count, OutputArray dst)
從幾個單通道陣列建立一個多通道陣列。
void extractChannel(InputArray src, OutputArray dst, int coi)
從 src 中提取單個通道(coi 是基於 0 的索引)
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
#define CV_32F
Definition interface.h:78
Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F)
從影像建立 4 維 blob。 可選地從中心調整影像大小並裁剪影像,...
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
int waitKey(int delay=0)
等待按鍵按下。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
從檔案載入影像。
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
將影像從一個顏色空間轉換為另一個顏色空間。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3