This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace cv; | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat_<Vec3b> image; | |
Mat grayImage; | |
Mat negativeImage(480, 640, CV_8UC1); | |
Mat_<Vec3b> colorNegativeImage(480, 640, CV_16U); | |
Mat_<Vec3b> manipulatedImage(480, 640, CV_16U); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int value; | |
double plus = 0.0, mult = 1.0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VideoCapture cap(0); // 0 for notebook camera, 1 for external camera | |
if(!cap.isOpened()) | |
{ | |
cout << "Camera error"; | |
return -1; | |
} | |
cap.open(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namedWindow("window", CV_WINDOW_AUTOSIZE); | |
namedWindow("grayWindow", CV_WINDOW_AUTOSIZE); | |
namedWindow("negativeGrayWindow", CV_WINDOW_AUTOSIZE); | |
namedWindow("negativeColorWindow", CV_WINDOW_AUTOSIZE); | |
namedWindow("linearWindow", CV_WINDOW_AUTOSIZE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// original image | |
cap >> image; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bw | |
cvtColor(image, grayImage, CV_BGR2GRAY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bw negative | |
for (int i = 0; i < image.rows; i++) { | |
for (int j = 0; j < image.cols; j++) { | |
negativeImage.at<uchar>(i,j) = 255 - grayImage.at<uchar>(i,j); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// color negative | |
for (int i = 0; i < image.rows; i++) { | |
for (int j = 0; j < image.cols; j++) { | |
for (int k = 0; k < 3; k++) { | |
colorNegativeImage.at<Vec3b>(i,j)[k] = 255 - image.at<Vec3b>(i,j)[k]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// image manipulation | |
for (int i = 0; i < image.rows; i++) { | |
for (int j = 0; j < image.cols; j++) { | |
for (int k = 0; k < 3; k++) { | |
value = image.at<Vec3b>(i,j)[k] * mult + plus; | |
if (value > 255) { | |
value = 255; | |
} | |
if (value < 0) { | |
value = 0; | |
} | |
manipulatedImage.at<Vec3b>(i,j)[k] = value; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imshow("window", image); | |
imshow("grayWindow", grayImage); | |
imshow("negativeGrayWindow", negativeImage); | |
imshow("negativeColorWindow", colorNegativeImage); | |
imshow("linearWindow", manipulatedImage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int c = waitKey(20); | |
switch(c) | |
{ | |
case 27: //ESC | |
destroyAllWindows(); | |
return 0; | |
break; | |
case 2621440: //down | |
plus -= 20; | |
break; | |
case 2490368: //up | |
plus += 20; | |
break; | |
case 2555904: //right | |
mult += 0.1; | |
break; | |
case 2424832: //left | |
mult -= 0.1; | |
break; | |
case 32: //space, reset parameters | |
plus = 0; | |
mult = 1; | |
break; | |
default: | |
break; | |
} |