1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
#include <vector>
#include <direct.h>
#include <algorithm> // for copy
#include <iterator> // for ostream_iterator
using namespace cv;
using namespace std;
Mat pic, gray, bw;
int rows, cols;
string path_in = "C:/Users/Dell/Desktop/";
string path_out = "C:/Users/Dell/Desktop/New Folder/";
int main(int argc, char** argv)
{
vector<cv::String> fn;
vector<cv::String> fo;
glob(path_in + "*.jpg", fn, false);
glob(path_out + "*.jpg", fo, false);
size_t count = fn.size();
for (size_t i = 0; i < 1; i++) //try for an image first, if works, then try for all images in folder
{
pic = imread(fn[i], CV_LOAD_IMAGE_COLOR);
cout << fn[i] << endl;
cvtColor(pic, gray, CV_BGR2GRAY);
//Canny(gray, gray, 50, 150, 3);
threshold(gray, bw, 128.0, 255.0, THRESH_BINARY);
//attempt
//std::vector<Point> myVec;
std::vector<Vec3d> myVec;
for (int r = 0; r < bw.rows; r++)
{
for (int c = 0; c < bw.cols; c++)
{
if (bw.at<uchar>(r, c) > 0) // white pixels
{
double z = 3.1209;
//myVec.push_back(Point(r, c));
myVec.push_back(Vec3d(r, c, z)); //add them to vector3d
//cout << " : " << myVec.at<Vec3d>myVec.r << " , " << myVec.at<Vec3d>myVec.c << " , " << z << endl;
}
}
}
//::copy(myVec.begin(), myVec.end(), std::ostream_iterator<Point>(std::cout << " " << std::endl));
std::copy(myVec.begin(), myVec.end(), std::ostream_iterator<Vec3d>(std::cout << " " << std::endl));
std::cout << "size: " << myVec.size() << '\n';
//attempt
/*
std::vector<Point> myVec;
findNonZero(bw == 255, myVec);
std::copy(myVec.begin(), myVec.end(), std::ostream_iterator<Point>(std::cout << " " << std::endl));
std::cout << "size: " << myVec.size() << '\n';
*/
//attempt
/*
Mat myVec;
findNonZero(bw, myVec);
const double z = 3.1209;
for (int p = 0; p < myVec.total(); p++)
{
//myVec.push_back((myVec.at<Point>(p).x), myVec.at<Point>(p).y);
//myVec.emplace_back(r, c);
cout << p << " : " << myVec.at<Point>(p).x << " , " << myVec.at<Point>(p).y << " , " << z << endl;
}
*/
waitKey(0);
}
system("PAUSE");
//return 0;
}
|