e07ava
Last Updated: February 25, 2016
·
3.75K
· dlion
28864ba1e7e4490c3e5e97e095d4b6c7

Simple steganography using OpenCV

#include <cv.h>
#include <highgui.h>
#include <string.h>
#include <stdlib.h>

int imgStega(IplImage *img, char *msg)
{
    int wid = img->width;
    uchar *data = (uchar*)img->imageData;

    int j,k=0; 
    int len = strlen(msg);

    if(img->nChannels != 3)
        return -1;

    for(j=0; j < wid; j+=3)
    {
        if(j == 0)
        {
            data[j*3] = '$';
            continue;
        }
        else
        { 
            if(k < len)
            {
                data[j*3] = msg[k];
                k++;
            }
            else
            {
                data[j*3] = '$';
                break;
            }
        }
    }

    return 0;
}

char *imgDestega(IplImage *img)
{
    int wid = img->width;
    uchar *data = (uchar*)img->imageData;

    int j,k=0;
    char find;
    char *buffer = NULL;

    for(j=0; j < wid; j+=3)
    {
        find = data[j*3];

        if(j == 0)
        {
            if(find != '$')
                exit(EXIT_FAILURE);
            else
                continue;
        }
        else
        {
            if(find == '$')
                break;
            else
            {
                buffer=(char*)realloc(buffer,(k+1)*sizeof(char));
                buffer[k] = find;
                k++;
            }
        }
    } 
    return buffer;
}

It support only PNG or BMP image.
You can use this functions for steganography a message into an image using OpenCV libraries.
The first function insert the message, the second function extract it for that.
For comment, issues or other you can contact me.
This source is avaiable on github: https://github.com/dlion/OStega

Say Thanks
Respond