Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Heasder inclusion
- #include <stdio.h>
- #include <cv.h>
- #include <highgui.h>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/video/tracking.hpp>
- #include <sstream>
- #include <string>
- #include <fstream>
- #include <pthread.h>
- #include <math.h>
- #include <iostream>
- #include <vector>
- //Namespace Declaration
- using namespace cv;
- using namespace std;
- void measureEdgeFromMiddleWrist(Mat edgeImage){
- Mat im_src = edgeImage.clone();
- Mat im_gray = im_src;
- Mat img_bw = im_gray > 250;
- Mat in = img_bw;
- imshow("IMAGE",img_bw);
- int firstRow = 1;
- bool oneEdgePixelFound = false;
- int edgePixelCounter=0;
- int edgeOnFirstLineRightLoc[1][2];
- int edgeCount=0;
- int total_img_width = img_bw.cols;
- int middle = total_img_width/2;
- cout << "total_img_width :" << total_img_width << endl;
- cout << "half of it : " << middle << endl;
- int cntr=0;
- // for(int row = 1; row <= 1; ++row) {
- for(int row = firstRow; row <= firstRow; ++row) {
- unsigned char* inp = in.ptr<unsigned char>(row);
- for (int col = middle; col < in.cols; ++col) {
- if (*inp++ == 0) {
- // std::cout << '1';
- } else {
- if(!oneEdgePixelFound){
- std::cout << "Row : " << row << " Col : " << col << " Value : 0 " << endl;
- int tmp = edgeCount++;
- edgeOnFirstLineRightLoc[tmp][0] =row ;
- edgeOnFirstLineRightLoc[tmp][1] =col ;
- edgePixelCounter++;
- if(edgePixelCounter==1){
- oneEdgePixelFound=true;
- }
- }
- }
- // std::cout << std::endl;
- }
- }
- int lastRow = img_bw.rows -1;
- oneEdgePixelFound = false;
- edgePixelCounter=0;
- int edgeOnLastLineRightLoc[1][2];
- edgeCount=0;
- for(int row = lastRow; row <= lastRow; ++row) {
- unsigned char* inp = in.ptr<unsigned char>(row);
- for (int col = middle; col < in.cols; ++col) {
- if (*inp++ == 0) {
- // std::cout << '1';
- } else {
- if(!oneEdgePixelFound){
- std::cout << "Row : " << row << " Col : " << col << " Value : 0 " << endl;
- int tmp = edgeCount++;
- edgeOnLastLineRightLoc[tmp][0] =row ;
- edgeOnLastLineRightLoc[tmp][1] =col ;
- edgePixelCounter++;
- if(edgePixelCounter==1){
- oneEdgePixelFound=true;
- }
- }
- }
- // std::cout << std::endl;
- }
- }
- // for (int i = 0; i < 2; ++i)
- // {
- for (int j = 0; j < 1; ++j)
- {
- cout << "Value at fisrt line Right Direction :" << edgeOnFirstLineRightLoc[j][1] << endl;
- }
- // }
- // for (int i = 0; i < 2; ++i)
- // {
- for (int j = 0; j < 1; ++j)
- {
- cout << "Value at Last line Right Direction :" << edgeOnLastLineRightLoc[j][1] << endl;
- }
- // }
- bool oneEdgePixelsFound_1 = false;
- int edgePixelCounter_1=0;
- // int edgeOnLastLineLeftLoc_1[2][2];
- int edgeOnFirstLineLeftLoc_1[1][1];
- int edgeCount_1=0;
- // for(int row = 1; row <= 1; ++row) {
- // for(int row = lastRow; row <= lastRow; ++row) {
- for(int row = firstRow; row <= firstRow; ++row) {
- unsigned char* inp = in.ptr<unsigned char>(row);
- for (int col = middle; col > 0; --col) {
- if (*inp++ == 0) {
- // std::cout << '1';
- } else {
- if(!oneEdgePixelsFound_1){
- std::cout << "Row : " << row << " Col : " << col << " Value : 0 " << endl;
- int tmp_1 = edgeCount_1++;
- edgeOnFirstLineLeftLoc_1[tmp_1][0]=row;
- edgeOnFirstLineLeftLoc_1[tmp_1][1]=col;
- edgePixelCounter_1++;
- if(edgePixelCounter_1==1){
- oneEdgePixelsFound_1=true;
- }
- }
- }
- // std::cout << std::endl;
- }
- }
- oneEdgePixelsFound_1 = false;
- edgePixelCounter_1=0;
- edgeCount_1=0;
- int edgeOnLastLineLeftLoc_1[1][1];
- for(int row = lastRow; row <= lastRow; ++row) {
- unsigned char* inp = in.ptr<unsigned char>(row);
- for (int col = middle; col > 0; --col) {
- if (*inp++ == 0) {
- // std::cout << '1';
- } else {
- if(!oneEdgePixelsFound_1){
- std::cout << "Row : " << row << " Col : " << col << " Value : 0 " << endl;
- int tmp_1 = edgeCount_1++;
- edgeOnLastLineLeftLoc_1[tmp_1][0]=row;
- edgeOnLastLineLeftLoc_1[tmp_1][1]=col;
- edgePixelCounter_1++;
- if(edgePixelCounter_1==1){
- oneEdgePixelsFound_1=true;
- }
- }
- }
- // std::cout << std::endl;
- }
- }
- for (int j = 0; j < 1; ++j)
- {
- cout << "Value at first line Left Direction :" << edgeOnFirstLineLeftLoc_1[j][1] << endl;
- }
- for (int j = 0; j < 1; ++j)
- {
- cout << "Value at Last line Left Direction :" << edgeOnLastLineLeftLoc_1[j][1] << endl;
- }
- int rowOneLengthRightPart = edgeOnFirstLineRightLoc[0][1] -80 ;
- int rowOneLengthLeftPart = 80 - edgeOnFirstLineLeftLoc_1[0][1];
- cout << "rowOneLengthRightPart : " << rowOneLengthRightPart << " rowOneLengthLeftPart :" << rowOneLengthLeftPart << endl ;
- int rowLastLengthRightPart = edgeOnLastLineRightLoc[0][1] - 80;
- int rowLastLengthLeftPart = 80 - edgeOnLastLineLeftLoc_1[0][1];
- cout << "rowLastLengthRightPart : " << rowLastLengthRightPart << " rowLastLengthLeftPart :" << rowLastLengthLeftPart << endl ;
- // cout << "Difference(s) : Fisrt row " << endl;
- int rowOneLength = 0;
- rowOneLength = rowOneLengthLeftPart + rowOneLengthRightPart;
- // for (int i = 0; i < 1; ++i){
- // for (int j = 0; j < 1; ++j){
- // cout << edgeOnFirstLineRightLoc[i+1][j+1] - edgeOnFirstLineRightLoc[i][j+1] << endl;
- // rowOneLength = edgeOnFirstLineRightLoc[i+1][j+1] - edgeOnFirstLineRightLoc[i][j+1];
- // }
- // }
- // cout << "Difference(s) Last Row : " << endl;
- int rowLastLength=0;
- rowLastLength = rowLastLengthLeftPart + rowLastLengthRightPart;
- // for (int i = 0; i < 1; ++i){
- // for (int j = 0; j < 1; ++j){
- // cout << edgeOnLastLineLeftLoc_1[i+1][j+1] - edgeOnLastLineLeftLoc_1[i][j+1] << endl;
- // rowLastLength = edgeOnLastLineLeftLoc_1[i+1][j+1] - edgeOnLastLineLeftLoc_1[i][j+1];
- // }
- // }
- int maxDist =0;
- if ( rowOneLength < rowLastLength){
- maxDist = rowLastLength;
- rowOneLength = maxDist;
- }else{
- maxDist = rowOneLength;
- rowLastLength = maxDist;
- }
- int avgLength = ( rowOneLength + rowLastLength ) / 2;
- cout << "Avegrage Difference(s) of two rows : " << avgLength << endl;
- int CdDiameter = 160;
- int ratio = 160/12;
- int wristSizeAvg = avgLength / ratio;
- cout << "Avegrage Wrist Size "<< wristSizeAvg << endl;
- waitKey(0);
- }
- int main(int argc, char const *argv[])
- {
- Mat input = imread(argv[1],-1);
- // Mat input_1;
- // cvtColor(input,input_1,CV_BGR2GRAY);
- // measureEdgeFromMiddleWrist(input_1);
- imshow("Input",input);
- measureEdgeFromMiddleWrist(input);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment