///
void ProcessSrcImg()
{
vector compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
CvScalar csWhite = cvScalar(255, 255, 255, 255);
CvScalar csEmpty = cvScalar(255, 255, 255, 0);
cv::Mat srcMat = cv::imread("D:\\img\\Radar.png", -1);
cv::Mat pMat = cv::imread("D:\\img\\img3.png", -1);
cv::Mat dstmat = cv::imread("D:\\img\\img3.png", -1);
int r = srcMat.rows;
int c = srcMat.cols;
//cv::namedWindow("11", cv::WINDOW_AUTOSIZE);
//cv::imshow("11", srcMat);
//cv::waitKey(0);
if (r == 0 || c == 0)
{
return;
}
CvScalar scCL,scCLT;
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
if (j == 400 && i == 720)
{
int a = 0;
}
GraphicsSystem::OpenCVUtils::GetPixelColor(srcMat, j, i, scCL);
GraphicsSystem::OpenCVUtils::GetPixelColor(pMat, j, i, scCLT);
/*if ( scCL.val[0] == 255 && scCL.val[1] == 255 && scCL.val[2] == 255)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(srcMat, j, i, csEmpty);
}*/
int b = scCL.val[0];
int g = scCL.val[1];
int r = scCL.val[2];
int alpha = scCL.val[3];
int b1 = scCLT.val[0];
int g1 = scCLT.val[1];
int r1 = scCLT.val[2];
int alpha1 = scCLT.val[3];
//d=(des);
//d<<=8;
//des1=(des*256-(des-srcu)*alpha)/256;
//alpha=(des1*256-des*256)/(srcu-des);
//d = 255-(((255-(*des))*(255-(*srcu)))>>8);
//des1=(des*255-(des-srcu)*alpha)/255;
//srcu=des-(des*255-des1*255)/alpha;
int blackalpha,bluealpha = 0,haveblue=0, alphaNew;
//blackalpha=255-g;
blackalpha=g;
if(g!=b){//have blue
bluealpha= 255 - r;//(r*255.0-0*255.0)/(255-0.0);
haveblue=1;
if(b<255)
{
haveblue=2;
}
}
else haveblue=0;
if(haveblue){//have blue
if(bluealpha)
{
b1=max(0, min(255,255-(255*255-b1*255)/bluealpha));
r1=max(0, min(255,0-(0*255-r1*255)/bluealpha));
g1=max(0, min(255,0-(0*255-g1*255)/bluealpha));
}
}
if(blackalpha != 0)
{
b1= max(0, min(255,0-(0*255-b1*255)/blackalpha));
r1= max(0, min(255,0-(0*255-r1*255)/blackalpha));
g1= max(0, min(255,0-(0*255-g1*255)/blackalpha));
}
alphaNew = 255;
if(r1 == 0 && g1 == 0)
{
b1 = 0;
}
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, j, i, cvScalar(b1, g1, r1, alphaNew));
}
}
// 转透明度, 补边界值
/*cv::namedWindow("22", cv::WINDOW_AUTOSIZE);
cv::imshow("22", dstmat);
cv::waitKey(0);*/
try {
cv::imwrite("D:\\img\\withbord.png", dstmat, compression_params);
}
catch (runtime_error& ex) {
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
//return;
int TR, TG, TB, TA;
for (int w = 0; w < c; ++w)
{
for (int h = 0; h < r; ++h)
{
if (w > 1034 && h > 437)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(0, 0, 0, 0));
continue;
}
if (w > 820 && h < 102)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(0, 0, 0, 0));
continue;
}
if (w <= 1 || h <= 1 || w >= c -2 || h >= r - 2)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(0, 0, 0, 0));
continue;
}
GraphicsSystem::OpenCVUtils::GetPixelColor(dstmat, w, h, scCL);
if (scCL.val[0] == scCL.val[1] && scCL.val[2] == scCL.val[1])
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(0, 0, 0, 0));
}
else
{
continue;
}
continue;
int index[24] = {w-1, h, w-1, h-1, w+1, h-1, w, h-1, w+1, h, w-1, h+1, w+1, h+1, w, h+1, w-2, h, w+2, h, w, h-2, w, h+2};
TR = TG = TB = 0;
for(int k = 0; k < 12; k++)
{
GraphicsSystem::OpenCVUtils::GetPixelColor(dstmat, index[k*2], index[k*2+1], scCLT);
if (scCL.val[0] != scCL.val[1] || scCL.val[2])//颜色为黑色、灰色、白色
{
TR = scCL.val[2];//((TR == 0 ? scCL.val[2] : TR) + scCL.val[2])/2;
TG = scCL.val[1];//((TG == 0 ? scCL.val[1] : TG) + scCL.val[1])/2;
TB = scCL.val[0];//((TB == 0 ? scCL.val[0] : TB) + scCL.val[0])/2;
break;
}
}
//if (TR > 0 || TB > 0 || TG >0)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(TB, TG, TR, 255));
}
/*else
{
GraphicsSystem::OpenCVUtils::SetPixelColor(dstmat, w, h, cvScalar(0, 0, 0, 0));
} */
}
}
/*vector compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);*/
double std_left = 110.0, std_right = 118.0, std_top = 37.5, std_bottom = 31.0;
double mct_left = 0, mct_top = 0, mct_right = 0, mct_bottom = 0;
CoordinateConvert::TransFormGeoToMercator(std_left, std_top, mct_left, mct_top);
CoordinateConvert::TransFormGeoToMercator(std_right, std_bottom, mct_right, mct_bottom);
cv::Mat mctMat = cv::imread("D:\\img\\img2.png", -1);
try {
cv::imwrite("D:\\img\\lnglat.png", dstmat, compression_params);
}
catch (runtime_error& ex) {
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
// 墨卡托转换
double geox = 0, geoy = 0, x = 0, y = 0;
CvScalar csColor;
for (int i = 0; i < dstmat.cols; ++i)
{
for (int j = 1; j < dstmat.rows; ++j)
{
GraphicsSystem::OpenCVUtils::SetPixelColor(mctMat, i, j, csEmpty);
x = i * (mct_right - mct_left)/dstmat.cols + mct_left;
y = mct_top - j * (mct_top - mct_bottom)/dstmat.rows;
CoordinateConvert::TransFormMercatorToGeo(x, y, geox, geoy);
int src_i = (geox - std_left) * dstmat.cols/(std_right - std_left);
int src_j = (std_top - geoy) * dstmat.rows/(std_top - std_bottom);
//srcMat.ptr(newj)[newi] = srcMat.ptr(j)[i];
// set color
if (src_i < 0 || src_j < 0)
{
continue;
}
GraphicsSystem::OpenCVUtils::GetPixelColor(dstmat, src_i, src_j, csColor);
if (csColor.val[0] == 255 && csColor.val[1] == 255 && csColor.val[2] == 255)
{
continue;
}
GraphicsSystem::OpenCVUtils::SetPixelColor(mctMat, i, j, csColor);
}
}
try {
cv::imwrite("D:\\img\\mct.png", mctMat, compression_params);
}
catch (runtime_error& ex) {
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
//cv::imwrite("D:\\img\\process.png", dstmat);
int a = 0;
return;
}