Advertisement
Guest User

imagexor

a guest
Oct 22nd, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.61 KB | None | 0 0
  1. #include <cv.hpp> //necessary because this code uses the OpenCV library
  2. #include "/usr/local/include/opencv2/highgui/highgui.hpp" //necessary because this code uses the OpenCV library
  3.  
  4. using namespace cv;
  5. using namespace std;
  6.  
  7. int main(int argc, char* argv[])
  8. {
  9. // /* for the purpose of exiting via keyboard input////////////////////////////////////////////////
  10. bool loop = true;
  11. Size size(320,240);//the dst image size,e.g.100x100
  12. // /* for the purpose of exiting via keyboard input////////////////////////////////////////////////
  13.  
  14. // /* storage(memory allocation) for images and data///////////////////////////////////////////////
  15. Mat image, random;
  16. // */ storage for images and data//////////////////////////////////////////////////////////////////
  17.  
  18. // /* declaration of char to hold input from the keyboard buffer///////////////////////////////////
  19. char KeyStroke;
  20. // */ declaration of char to hold input from the keyboard buffer///////////////////////////////////
  21.  
  22. //prepare image source/////////////////////////////////////////////////////////////////////////////
  23. VideoCapture cap;//assigning camera and proportions
  24. cap.open(0);//starting webcam feed
  25. //prepare image source/////////////////////////////////////////////////////////////////////////////
  26.  
  27. /* video input specific////////////////////////////////////////////////////////////////////////////
  28. //cap.set(3, 320);
  29. //cap.set(4, 240);
  30. //cap.set(5,5);
  31. //cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
  32. //cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
  33. */// video input specific//////////////////////////////////////////////////////////////////////////
  34.  
  35. namedWindow("original",1);//creating window for unmodified image
  36. namedWindow("random",1);//creating window for "random noise"
  37. namedWindow("xor",1);//creating window for obfuscated output
  38. namedWindow("unxor",1);//creating window for deobfuscated image
  39.  
  40.  
  41.  
  42. while(loop == true)
  43. {
  44.  
  45. try
  46. {
  47.  
  48. // /* //read "image" from webcam or video//////////////////////////////////////////////////////////
  49. cap>>image;
  50. // */ //read "image" from webcam or video//////////////////////////////////////////////////////////
  51.  
  52. // /* //generate Mat full of random noise//////////////////////////////////////////////////////////
  53. random = Mat(240, 320, CV_8UC3);
  54. randu(random, Scalar::all(0), Scalar::all(255));
  55. // */ //generate Mat full of random noise//////////////////////////////////////////////////////////
  56.  
  57. // /* //resize image///////////////////////////////////////////////////////////////////////////////
  58. resize(image,image,size);//resize image
  59. // */ //resize image///////////////////////////////////////////////////////////////////////////////
  60.  
  61. // /* //recycled code//////////////////////////////////////////////////////////////////////////////
  62. KeyStroke = cvWaitKey(100); //get keyboard input
  63.  
  64. if(KeyStroke==' '){
  65. break;
  66. }
  67. // */ //recycled code//////////////////////////////////////////////////////////////////////////////
  68.  
  69. // /* //placeholder creation///////////////////////////////////////////////////////////////////////
  70. Mat imageT, randomT, image2; //placeholders to preserve "image" and "random" in their original conditions for comparison
  71. vector<Mat> channels; //bitwise_xor placeholder for "imageT"
  72. vector<Mat> channels2; //bitwise_xor placeholder for "randomT"
  73. vector<Mat> channels3; //bitwise_xor placeholder for "image2"
  74. // */ //placeholder creation///////////////////////////////////////////////////////////////////////
  75.  
  76. // /* //prepare the input Mat(s) for bitwise_xor processing////////////////////////////////////////
  77. cvtColor(image, imageT, CV_BGR2HSV);//cvtColor conversion of "image"(type: Mat) to HSV colorspace "imageT"(type: Mat)
  78. cvtColor(random, randomT, CV_BGR2HSV);//cvtColor conversion of "random"(type: Mat) to HSV colorspace "randomT"(type: Mat)
  79. cvtColor(image, image2, CV_BGR2HSV);//cvtColor conversion of "image"(type: Mat) to HSV colorspace "image2"(type: Mat)
  80. // */ //prepare the input Mat(s) for bitwise_xor processing////////////////////////////////////////
  81.  
  82. // /* //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
  83. split(imageT, channels);
  84. Mat HueI(channels[0]); //Create "Hue" channel
  85. Mat SatI(channels[1]); //Create "Sat" channel
  86. Mat VeeI(channels[2]); //Create "Vee" channel
  87. // */ //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
  88.  
  89.  
  90. // /* //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
  91. split(randomT, channels2);
  92. Mat HueR(channels2[0]); //Create "Hue" channel
  93. Mat SatR(channels2[1]); //Create "Sat" channel
  94. Mat VeeR(channels2[2]); //Create "Vee" channel
  95. // */ //prepare the necessary vector<mat> for adding the "random noise" to the output//////////////
  96.  
  97.  
  98. // /* //prepare the necessary vector<mat> for holding the output from xor//////////////////////////
  99. split(image2, channels3);
  100. Mat Hue2(channels3[0]); //Create "Hue" channel
  101. Mat Sat2(channels3[1]); //Create "Sat" channel
  102. Mat Vee2(channels3[2]); //Create "Vee" channel
  103. // */ //prepare the necessary vector<mat> for holding the output from xor//////////////////////////
  104.  
  105. // /* //xor "random noise" with the input mat to obfuscate the image from its original appearance//
  106. 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]
  107. 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]
  108. 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]
  109. // */ //xor "random noise" with the input mat to obfuscate the image from its original appearance//
  110.  
  111. // /* //show the obfuscated output in window "xor"/////////////////////////////////////////////////
  112. merge(channels3, image2);
  113. cvtColor(image2, image2, CV_HSV2BGR);//GPU namespace cvtColor conversion of "oclImage"(type: Mat) to HSV colorspace "oclSrc_hsv"(type: Mat)
  114. imshow("xor",image2);//show the obfuscated output in window "xor"
  115. // */ //show the obfuscated output in window "xor"/////////////////////////////////////////////////
  116.  
  117. // /* //prepare the obfuscated output for removal of the "random noise"////////////////////////////
  118. cvtColor(image2, image2, CV_BGR2HSV);//cvtColor conversion of "image2"(type: Mat) to HSV colorspace "image2"(type: Mat)
  119. // */ //prepare the obfuscated output for removal of the "random noise"////////////////////////////
  120.  
  121. // /* //prepare the necessary vector<mat> for removing the "random noise" from the output//////////
  122. split(image2, channels3);
  123.  
  124. Mat Hue3(channels3[0]); //Create "Hue" channel
  125. Mat Sat3(channels3[1]); //Create "Sat" channel
  126. Mat Vee3(channels3[2]); //Create "Vee" channel
  127. // */ //prepare the necessary vector<mat> for removing the "random noise" from the output//////////
  128.  
  129. // /* //xor same "random noise" with the output mat to return the image to its original appearance/
  130. 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]
  131.  
  132. 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]
  133.  
  134. 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]
  135. // /* //xor same "random noise" with the output mat to return the image to its original appearance/
  136.  
  137. // /* //show the deobfuscated output in window "unxor"/////////////////////////////////////////////
  138. merge(channels3, image2); //recombine the 3x HSV Channels of "channel3"(type: vector<Mat>) into "image2"(type: Mat)
  139. cvtColor(image2, image2, CV_HSV2BGR);//cvtColor conversion of "image2"(type: Mat) to BGR colorspace "image2"(type: Mat)
  140. imshow("unxor",image2);//normal window show webcam or video
  141. // */ //show the deobfuscated output in window "unxor"/////////////////////////////////////////////
  142.  
  143. // /* //show the original input in window "original" and "random noise" in window "random"/////////
  144. cvtColor(imageT, image, CV_HSV2BGR);//cvtColor conversion of "randomT"(type: Mat) to BGR colorspace "random"(type: Mat)
  145. cvtColor(randomT, random, CV_HSV2BGR);//cvtColor conversion of "randomT"(type: Mat) to BGR colorspace "random"(type: Mat)
  146. imshow("original",image);//normal window show webcam or video
  147. imshow("random",random);//normal window show webcam or video
  148. // /* //show the original input in window "original" and "random noise" in window "random"/////////
  149. }
  150.  
  151. // /* //recycled code//////////////////////////////////////////////////////////////////////////////
  152. catch (Exception& e)//error checking
  153. {
  154. const char* err_msg = e.what();
  155. std::cout << "exception caught: imshow:\n" << err_msg << std::endl;
  156. }
  157.  
  158. char key = waitKey(33) & 0xFF;//checking for key press
  159. if (key == 'q')//press q to quit
  160. {
  161. //cap.release();
  162. image.release();
  163. loop = false;
  164. }
  165. // */ //recycled code///////////////////////////////////////////////////////////////////
  166. }
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement