Below is C++ code using opencv and running it through the terminal. The code so
ID: 663526 • Letter: B
Question
Below is C++ code using opencv and running it through the terminal. The code so far brings up the original pic, Pic with edit, Pic with 2nd edit, then the points of the line. I have been looking for a way to implement the opencv CVSnakeImage within the code with the point printed out from the line.
//USED TO OPEN IMAGE
#include "opencv2/highgui/highgui.hpp"
//USED TO GAUSSIAN FILTER
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;
void myLine(Mat copy, Point pt1, Point pt2);
void Extract(Mat copy, Point pt1, Point pt2);
int main(){
//CODE TO LOADING IMAGE
Mat frame = imread ("First.png", CV_LOAD_IMAGE_UNCHANGED);
//putText(frame,"First", Point (120, 330), 1, 4, CV_RGB(255, 0, 0), 3, 8, false);
int rows = frame.rows;
int cols = frame.cols;
//If the image wont appear
if (frame.empty()){
cout<<"No Image!"<<endl;
return -1;
}
//Displaying image without filter (Orignal))
imshow ("Original", frame);
waitKey(0);
//Cloning
Mat copy = frame.clone();
//Gaussian Filter (Originial Image, Clone Image, KSize(MUST BE POSITIVE OR ODD OR ZERO width, height), sigmaX, sigmaY
GaussianBlur(frame, copy, Size(9, 9), 0, 0);
//Display the blurred image
imshow("Blurred Image", copy);
waitKey(0);
Point pt1, pt2;
pt1.x = 0;
pt1.y = 95;
pt2.x = 900;
pt2.y = 95;
//Calling Function (image, starting point, ending point)
//(X,Y)
// myLine(copy, Point(0, 95), Point (1000, 95));
//
// return 0;
Extract (copy, pt1, pt2);
imshow("After Line", copy);
waitKey(0);
return 0;
}
void myLine (Mat copy, Point start, Point end){
int thickness = 2;
int lineType = 8;
line (copy, start, end, Scalar(0,0,0), thickness, lineType);
}
void Extract (Mat copy, Point pt1, Point pt2)
{
myLine(copy, Point(pt1), Point (pt2));
ofstream myfile;
myfile.open ("Test1.txt");
Point copypt1;
copypt1.x = pt1.x;
for (int i = pt1.x; i <=pt2.x; i++){
for (int j=pt1.y; j<=pt2.y ; j++){
copypt1.y = pt1.y;
myfile <<copypt1;
}
copypt1.x = copypt1.x +1;
cout<<" ";
}
myfile.close();
}