在图像opencv上使用dct嵌入水印

时间:2014-11-29 11:53:55

标签: c++ opencv watermark

我想使用带有c ++和opencv的dct将水印嵌入到图像中。 我将图像分割成8x8块并将dct应用于每个块。 现在我不知道下一步该做什么,有人能给我一些暗示或帮助我吗?

到目前为止,这是我的工作。

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;
}

0 个答案:

没有答案