Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cv.hpp> //necessary because this code uses the OpenCV library
- #include "/usr/local/include/opencv2/highgui/highgui.hpp" //necessary because this code uses the OpenCV library
- using namespace cv;
- using namespace std;
- int main(int argc, char* argv[])
- {
- // /* for the purpose of exiting via keyboard input////////////////////////////////////////////////
- bool loop = true;
- Size size(320,240);//the dst image size,e.g.100x100
- // /* for the purpose of exiting via keyboard input////////////////////////////////////////////////
- // /* storage(memory allocation) for images and data///////////////////////////////////////////////
- Mat image, random;
- // */ storage for images and data//////////////////////////////////////////////////////////////////
- // /* declaration of char to hold input from the keyboard buffer///////////////////////////////////
- char KeyStroke;
- // */ declaration of char to hold input from the keyboard buffer///////////////////////////////////
- //prepare image source/////////////////////////////////////////////////////////////////////////////
- VideoCapture cap;//assigning camera and proportions
- cap.open(0);//starting webcam feed
- //prepare image source/////////////////////////////////////////////////////////////////////////////
- /* video input specific////////////////////////////////////////////////////////////////////////////
- //cap.set(3, 320);
- //cap.set(4, 240);
- //cap.set(5,5);
- //cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
- //cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
- */// video input specific//////////////////////////////////////////////////////////////////////////
- namedWindow("original",1);//creating window for unmodified image
- namedWindow("random",1);//creating window for "random noise"
- namedWindow("xor",1);//creating window for obfuscated output
- namedWindow("unxor",1);//creating window for deobfuscated image
- while(loop == true)
- {
- try
- {
- // /* //read "image" from webcam or video//////////////////////////////////////////////////////////
- cap>>image;
- // */ //read "image" from webcam or video//////////////////////////////////////////////////////////
- // /* //generate Mat full of random noise//////////////////////////////////////////////////////////
- random = Mat(240, 320, CV_8UC3);
- randu(random, Scalar::all(0), Scalar::all(255));
- // */ //generate Mat full of random noise//////////////////////////////////////////////////////////
- // /* //resize image///////////////////////////////////////////////////////////////////////////////
- resize(image,image,size);//resize image
- // */ //resize image///////////////////////////////////////////////////////////////////////////////
- // /* //recycled code//////////////////////////////////////////////////////////////////////////////
- KeyStroke = cvWaitKey(100); //get keyboard input
- if(KeyStroke==' '){
- break;
- }
- // */ //recycled code//////////////////////////////////////////////////////////////////////////////
- // /* //placeholder creation///////////////////////////////////////////////////////////////////////
- Mat imageT, randomT, image2; //placeholders to preserve "image" and "random" in their original conditions for comparison
- vector<Mat> channels; //bitwise_xor placeholder for "imageT"
- vector<Mat> channels2; //bitwise_xor placeholder for "randomT"
- vector<Mat> channels3; //bitwise_xor placeholder for "image2"
- // */ //placeholder creation///////////////////////////////////////////////////////////////////////
- // /* //prepare the input Mat(s) for bitwise_xor processing////////////////////////////////////////
- cvtColor(image, imageT, CV_BGR2HSV);//cvtColor conversion of "image"(type: Mat) to HSV colorspace "imageT"(type: Mat)
- cvtColor(random, randomT, CV_BGR2HSV);//cvtColor conversion of "random"(type: Mat) to HSV colorspace "randomT"(type: Mat)
- cvtColor(image, image2, CV_BGR2HSV);//cvtColor conversion of "image"(type: Mat) to HSV colorspace "image2"(type: Mat)
- // */ //prepare the input Mat(s) for bitwise_xor processing////////////////////////////////////////
- // /* //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
- split(imageT, channels);
- Mat HueI(channels[0]); //Create "Hue" channel
- Mat SatI(channels[1]); //Create "Sat" channel
- Mat VeeI(channels[2]); //Create "Vee" channel
- // */ //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
- // /* //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
- split(randomT, channels2);
- Mat HueR(channels2[0]); //Create "Hue" channel
- Mat SatR(channels2[1]); //Create "Sat" channel
- Mat VeeR(channels2[2]); //Create "Vee" channel
- // */ //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
- // /* //prepare the necessary vector<mat> for holding the output from xor//////////////////////////
- split(image2, channels3);
- Mat Hue2(channels3[0]); //Create "Hue" channel
- Mat Sat2(channels3[1]); //Create "Sat" channel
- Mat Vee2(channels3[2]); //Create "Vee" channel
- // */ //prepare the necessary vector<mat> for holding the output from xor//////////////////////////
- // /* //xor "random noise" with the input mat to obfuscate the image from its original appearance//
- bitwise_xor(HueI, HueR, Hue2);//xor "HueI"(type: Mat) from "channels[0]"(type: vector<Mat>)<-[composed of "imageT" split() output] with "HueR"(type: Mat)<-from "channels2[0]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- bitwise_xor(SatI, SatR, Sat2);//xor "SatI"(type: Mat) from "channels[0]"(type: vector<Mat>)<-[composed of "imageT" split() output] with "SatR"(type: Mat)<-from "channels2[1]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- bitwise_xor(VeeI, VeeR, Vee2);//xor "VeeI"(type: Mat) from "channels[0]"(type: vector<Mat>)<-[composed of "imageT" split() output] with "VeeR"(type: Mat)<-from "channels2[2]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- // */ //xor "random noise" with the input mat to obfuscate the image from its original appearance//
- // /* //show the obfuscated output in window "xor"/////////////////////////////////////////////////
- merge(channels3, image2);
- cvtColor(image2, image2, CV_HSV2BGR);//GPU namespace cvtColor conversion of "oclImage"(type: Mat) to HSV colorspace "oclSrc_hsv"(type: Mat)
- imshow("xor",image2);//show the obfuscated output in window "xor"
- // */ //show the obfuscated output in window "xor"/////////////////////////////////////////////////
- // /* //prepare the obfuscated output for removal of the "random noise"////////////////////////////
- cvtColor(image2, image2, CV_BGR2HSV);//cvtColor conversion of "image2"(type: Mat) to HSV colorspace "image2"(type: Mat)
- // */ //prepare the obfuscated output for removal of the "random noise"////////////////////////////
- // /* //prepare the necessary vector<mat> for removing the "random noise" from the output//////////
- split(image2, channels3);
- Mat Hue3(channels3[0]); //Create "Hue" channel
- Mat Sat3(channels3[1]); //Create "Sat" channel
- Mat Vee3(channels3[2]); //Create "Vee" channel
- // */ //prepare the necessary vector<mat> for removing the "random noise" from the output//////////
- // /* //xor same "random noise" with the output mat to return the image to its original appearance/
- bitwise_xor(Hue3, HueR, Hue3);//xor "Hue3"(type: Mat) from "channels3[0]"(type: vector<Mat>)<-[composed of "image2" split() output] with "HueR"(type: Mat)<-from "channels2[0]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- bitwise_xor(Sat3, SatR, Sat3);//xor "Sat3"(type: Mat) from "channels3[1]"(type: vector<Mat>)<-[composed of "image2" split() output] with "SatR"(type: Mat)<-from "channels2[1]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- bitwise_xor(Vee3, VeeR, Vee3);//xor "Vee3"(type: Mat) from "channels3[2]"(type: vector<Mat>)<-[composed of "image2" split() output] with "VeeR"(type: Mat)<-from "channels2[1]"(type: vector<Mat>)<-[composed of "randomT" split() output]
- // /* //xor same "random noise" with the output mat to return the image to its original appearance/
- // /* //show the deobfuscated output in window "unxor"/////////////////////////////////////////////
- merge(channels3, image2); //recombine the 3x HSV Channels of "channel3"(type: vector<Mat>) into "image2"(type: Mat)
- cvtColor(image2, image2, CV_HSV2BGR);//cvtColor conversion of "image2"(type: Mat) to BGR colorspace "image2"(type: Mat)
- imshow("unxor",image2);//normal window show webcam or video
- // */ //show the deobfuscated output in window "unxor"/////////////////////////////////////////////
- // /* //show the original input in window "original" and "random noise" in window "random"/////////
- cvtColor(imageT, image, CV_HSV2BGR);//cvtColor conversion of "randomT"(type: Mat) to BGR colorspace "random"(type: Mat)
- cvtColor(randomT, random, CV_HSV2BGR);//cvtColor conversion of "randomT"(type: Mat) to BGR colorspace "random"(type: Mat)
- imshow("original",image);//normal window show webcam or video
- imshow("random",random);//normal window show webcam or video
- // /* //show the original input in window "original" and "random noise" in window "random"/////////
- }
- // /* //recycled code//////////////////////////////////////////////////////////////////////////////
- catch (Exception& e)//error checking
- {
- const char* err_msg = e.what();
- std::cout << "exception caught: imshow:\n" << err_msg << std::endl;
- }
- char key = waitKey(33) & 0xFF;//checking for key press
- if (key == 'q')//press q to quit
- {
- //cap.release();
- image.release();
- loop = false;
- }
- // */ //recycled code///////////////////////////////////////////////////////////////////
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement