基于opencv图像的dct水印嵌入 我想用C++和OpenCV将DCT嵌入到图像中。 我将图像分割成8x8块,并对每个块应用dct。 现在我不知道下一步该怎么办,谁能给我一些提示或帮助我
这是我到目前为止的工作基于opencv图像的dct水印嵌入 我想用C++和OpenCV将DCT嵌入到图像中。 我将图像分割成8x8块,并对每个块应用dct。 现在我不知道下一步该怎么办,谁能给我一些提示或帮助我,c++,opencv,watermark,C++,Opencv,Watermark,这是我到目前为止的工作 int main() { Mat originalImage; originalImage = imread("image.jpg"); if( !originalImage.data ) { std::cout<< "Error loading original image!"<<std::endl; return -1; } cout << "Wor
int main() {
Mat originalImage;
originalImage = imread("image.jpg");
if( !originalImage.data )
{
std::cout<< "Error loading original image!"<<std::endl;
return -1;
}
cout << "Working on image from image.jpg" << endl;
/// Create Windows
namedWindow("Original", 1);
imshow( "Original", originalImage );
int x = 0; int y = 0;
moveWindow("Original", x, y);
imshow("Original", originalImage);
x += 100; y += 100;
int width = originalImage.size().width;
int height = originalImage.size().width;
cout << "Original image Width x Height is " << width << "x" << height << endl;
// Leave original alone, work on a copy
Mat dctImage = originalImage.clone();
// Step through the copied image with rectangles size 8x8
// For each block, split into planes, do dct, and merge back
// into the block. (This will affect the image from
// which the block is selected each time.)
for (int i = 0; i < height; i += 8)
{
for (int j = 0; j < width; j+= 8)
{
Mat block = dctImage(Rect(i, j, 8, 8));
vector<Mat> planes;
split(block, planes);
vector<Mat> outplanes(planes.size());
for (size_t k = 0; k < planes.size(); k++)
{
planes[k].convertTo(planes[k], CV_32FC1);
dct(planes[k], outplanes[k]);
outplanes[k].convertTo(outplanes[k], CV_8UC1);
}
merge(outplanes, block);
}
}
namedWindow("dctBlockImage");
moveWindow("dctBlockImage", x, y);
imshow("dctBlockImage", dctImage);
x += 100; y += 100;
waitKey();
destroyAllWindows();
return 0;
}
顺便说一句,对于int i=0;i<身高;i+=8将溢出。请运行调试生成。还有:Rectj,我,8,8谢谢你。我会修好的。但是我接下来应该做什么来嵌入水印呢?你可能需要解释一下:使用dct将水印嵌入到图像中?我使用dct来转换图像。现在我想在图像中嵌入水印,我该怎么做?