diff --git a/Shivam/Gazebo/my_robots/model.config b/Shivam/Gazebo/my_robots/model.config new file mode 100644 index 0000000..3d21fee --- /dev/null +++ b/Shivam/Gazebo/my_robots/model.config @@ -0,0 +1,15 @@ + + + My Robot + 1.0 + model.sdf + + + My Name + me@my.email + + + + My awesome robot. + + diff --git a/Shivam/Gazebo/my_robots/model.sdf b/Shivam/Gazebo/my_robots/model.sdf new file mode 100644 index 0000000..d2f9fc4 --- /dev/null +++ b/Shivam/Gazebo/my_robots/model.sdf @@ -0,0 +1,118 @@ + + + + false + + 0 0 0.1 0 0 0 + + + + + 0.4 0.2 0.1 + + + + + + + + .4 .2 .1 + + + + + + + + -0.15 0 -.05 0 0 0 + + + 0.05 + + + + + + + + -0.15 0 -0.05 0 0 0 + + + 0.05 + + + + + + 0 + 0 + 1.0 + 1.0 + + + + + + + + 0.1 0.13 0.1 0 1.5707 1.5707 + + + + 0.1 + 0.05 + + + + + + + 0.1 + 0.05 + + + + + + 0.1 -0.13 0.1 0 1.5707 1.5707 + + + + 0.1 + 0.05 + + + + + + + .1 + .05 + + + + + + + 0 0 -0.03 0 0 0 + left_wheel + chassis + + 0 1 0 + + + + + 0 0 0.03 0 0 0 + right_wheel + chassis + + 0 1 0 + + + + + + + + diff --git a/Shivam/Oops1/Oops.cpp b/Shivam/Oops1/Oops.cpp new file mode 100644 index 0000000..3f9c59b --- /dev/null +++ b/Shivam/Oops1/Oops.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include "findCentroid.cpp" +#include "blobDetect.cpp" +#include "queue.h" + +image img_class; + +int main() +{ + int flag1=1, flag2=1; + int count=0; + cv::Mat bin,edit; + bin=binary(img_class.img,190.0); + img_class.img_bin=bin; + count= img_class.bfs(); + img_class.count=count; + img_class.findCentroid(); + while (flag1==1 && flag2==1) + { + flag1=img_class.updatepos1(); + flag2= img_class.updatepos2(); + img_class.printScore(); + } + + std::cout<<"GAME OVER"; + return 0; +} \ No newline at end of file diff --git a/Shivam/Oops1/Oops_class.h b/Shivam/Oops1/Oops_class.h new file mode 100644 index 0000000..f21baca --- /dev/null +++ b/Shivam/Oops1/Oops_class.h @@ -0,0 +1,59 @@ +#ifndef Oops_class_h +#define Oops_class_h + +#include +#include +#include + +class pos + { + public: + pos() + { + x=0,y=0;colour=0; + } + int x; + int y; + int colour; + }; + +class image + { int score1; + int score2; + pos currentpos1; + pos currentpos2; + + public: + int count; + cv::Mat img; + cv::Mat img_bin; + int **visited; + image(); + pos *centroid; + int bfs(); + int updatepos1(); + int updatepos2(); + void findCentroid(); + void printScore(); + }; + + image::image() + { + score1=0,score2=0; + count=0; + score1=0; + score2=0; + img = cv::imread("/home/aries/Desktop/1.jpg",0); + int rows=img.rows; + int cols=img.cols; + visited= new int*[rows]; + for(int j=0;j +#include +#include +#include +#include "Oops_class.h" +#include "queue.h" + + + +cv::Mat binary(cv::Mat img,float threshold) +{ cv::Mat img_gray,img_bin; + img=cv::imread("/home/aries/Desktop/1.jpg",1); + cvtColor(img,img_gray,CV_RGB2GRAY); + cv::threshold(img_gray,img_bin,threshold,255.0,cv::THRESH_BINARY); + cv::imwrite("img_bin3.jpg",img_bin); + return img_bin; + +} + +int image::bfs() +{ + queue q; + int x=0,y=0; + int cols=img_bin.cols, rows=img_bin.rows; + int count=1; + + for(int j=0;j(i,j))==0) + { + if(visited[i][j]==-1) + { + q.enqueue(i,j); + q.queueFront(&x,&y); + visited[i][j]=0; + + while(!q.isEmpty()) + { q.queueFront(&x,&y); + q.dequeue(); + for(int l=y-1;l<=y+1;l++) + for(int k=x-1;k<=x+1;k++) + { + if(k>0 && k0 && l(i,j)==0) + { + q.enqueue(k,l); + visited[k][l]=count; + + } + + } + visited[x][y]=count; + } + count++; + std::cout< +#include +#include +#include +#include "Oops_class.h" + + +//Has definitions of functions findCentroid, calcDist, Updatepos1, Updatepos2, printScore +void image::findCentroid() +{ + int *pixels= new int[count]; + int blobno=0; + int rows=img_bin.rows; + int cols=img_bin.cols; + for(int j=0;j(centre.x,centre.y); + if(point[0]>200 && point[1]<100 && point[2]<100) + (centroid[i]).colour= 0; + else if(point[0]<100 && point[1]>200 && point[2]<100) + (centroid[i]).colour= 1; + else if(point[0]<100 && point[1]<100 && point[2]>200) + (centroid[i]).colour= 2; + } +} + + +float calcDist(pos a, pos b) //Calculating only the square of the distance +{ + float dist=0; + dist= (a.x- b.x)*(a.x- b.x) + (a.y- b.y)*(a.y- b.y); + return dist; +} +int image::updatepos1() +{ + float temp=0; + float minDist=2*(img.rows)*(img.cols)*(img.rows)*(img.cols); + pos nearestC; + int dice1=0; + dice1=rand()%6 +1; + std::cout<<"Player 1's throw is "<x=x; + t->y=y; + t->next=NULL; + if(isEmpty()){ + front=t; + rear=front; + } + else + { + rear->next=t; + rear=t; + rear->next=NULL; + } +} +void queue::queueFront(int *x, int *y) +{ + *x=front->x; + *y=front->y; + return; +} +void queue::dequeue() +{ + node *t; + if(isEmpty()){ + std::cout<<"Queue Underflow"<next; + delete t; +} diff --git a/Shivam/Oops1/queue.h b/Shivam/Oops1/queue.h new file mode 100644 index 0000000..b12fcf8 --- /dev/null +++ b/Shivam/Oops1/queue.h @@ -0,0 +1,27 @@ +#ifndef queue_h +#define queue_h +#include +#include "queue.cpp" + +struct node +{ public: + int x; + int y; + node *next; +}; + +class queue +{ + node *front, *rear; +public: + queue(){front=NULL; + rear=NULL;} + int isEmpty(); + void enqueue(int x, int y); + void queueFront(int *x, int *y); + void dequeue(); + +}; + +#endif + diff --git a/Shivam/SampleImage/lane.png b/Shivam/SampleImage/lane.png new file mode 100644 index 0000000..4b70c92 Binary files /dev/null and b/Shivam/SampleImage/lane.png differ diff --git a/Shivam/laneDetect/CMakeLists.txt b/Shivam/laneDetect/CMakeLists.txt new file mode 100644 index 0000000..a06c2e9 --- /dev/null +++ b/Shivam/laneDetect/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8) +project( DisplayImage ) +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -pedantic -g -O3 -std=c++0x") +endif() +find_package( OpenCV REQUIRED ) +include_directories( ${OpenCV_INCLUDE_DIR} ) + +add_executable(combolane combolane.cpp ) +target_link_libraries( combolane ${OpenCV_LIBS} ) diff --git a/Shivam/laneDetect/combolane.cpp b/Shivam/laneDetect/combolane.cpp new file mode 100644 index 0000000..37e76ab --- /dev/null +++ b/Shivam/laneDetect/combolane.cpp @@ -0,0 +1,321 @@ +#include +#include +#include +#include + +class pos + { + public: + pos() + { + x=0,y=0;colour=0; + } + int x; + int y; + int colour; + }; + +class node +{ +public: + int x; + int y; + node *next; +}; + +class queue +{ + node *front, *rear; +public: + queue() + { + front=NULL; + rear=NULL; + } + int isEmpty(); + void enqueue(int, int); + void queueFront(int*, int*); + void dequeue(); + +}; + +class img_process +{ +public: + cv::Mat img; + // node *lane1, *lane2; + int **visited; + pos *centroid; + int count; + cv::Mat binary(cv::Mat, float threshold); + void bfs(cv::Mat img_bin); + void findCentroid(cv::Mat img_bin); + cv::Mat colour(cv::Mat, int, int); + cv::Mat link(cv::Mat img_bin, int thresh); + // img_process(); + +}; + +/*img_process::img_process() //Possible source of error +{ + lane1=NULL; + lane2=NULL; +}*/ + +int queue::isEmpty() +{ + if(front==NULL) + return 1; + else return 0; +} + +void queue::enqueue(int y, int x) +{ + + node *t=new node; + t->x=x; + t->y=y; + t->next=NULL; + if(isEmpty()){ + front=t; + rear=front; + } + else + { + rear->next=t; + rear=t; + rear->next=NULL; + } +} +void queue::queueFront(int *y, int *x) +{ + *x=front->x; + *y=front->y; +} +void queue::dequeue() +{ + node *t; + if(isEmpty()){ + std::cout<<"Queue Underflow"<next; + delete t; +} + +float dist_sq(pos a, pos b) +{ + return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y); +} + +cv::Mat img_process::colour(cv::Mat img_bin,int val, int rgb) //rgb= 1 or 2 depending on lane colour +{ + for(int i=0;i(i,j); + point[rgb]= 255; + } + } + return img_bin; +} + +cv::Mat img_process::binary(cv::Mat img_gray,float threshold) +{ cv::Mat img_bin; + cv::threshold(img_gray,img_bin,threshold,255,cv::THRESH_BINARY); + cv::imwrite("img_bin4.jpg",img_bin); + return img_bin; +} + +void img_process::bfs(cv::Mat img_bin) +{ + int **visited=new int*[img_bin.rows]; + for(int i=0;i(j,i))==255) + { + if(visited[j][i]==-1) + { + q.enqueue(j,i); + q.queueFront(&y,&x); + visited[j][i]=0; + while(!q.isEmpty()) + { q.queueFront(&y,&x); + q.dequeue(); + for(int l=y-1;l<=y+1;l++) + for(int k=x-1;k<=x+1;k++) + { + if(k>0 && k0 && l(l,k)==255) + { + q.enqueue(l,k); + visited[l][k]=count; + + } + } + visited[y][x]=count; + } + count++; + } + } + } + cv::imshow("images",img_bin); +} + +void img_process::findCentroid(cv::Mat img_bin) +{ + int *pixels= new int[count]; + int blobno=0; + int rows=img_bin.rows; + int cols=img_bin.cols; + + for(int j=0;j(centre.x,centre.y); + if(point[0]>150 && point[1]<100 && point[2]<100) + (centroid[i]).colour= 0; + else if(point[0]<100 && point[1]>150 && point[2]<100) + (centroid[i]).colour= 1; + else if(point[0]<100 && point[1]<100 && point[2]>150) + (centroid[i]).colour= 2; + } +} + + +cv::Mat img_process::link(cv::Mat img_bin,int thresh) +{ + float thresh_sq=thresh*thresh; + int j=1, flag=0,val=0; + float temp=0, temp_pos=0; + // lane1.x= &(centroid[1]).x; + //lane1.y= &(centroid[1]).y; + for(int i=1;i<=count;i++) + { val= visited[centroid[i].y][centroid[i].x]; + + img_bin=colour(img_bin, val,1); + visited[(centroid[i]).y][(centroid[i]).x]=1; + cv::namedWindow("image",CV_WINDOW_AUTOSIZE); + cv::imshow("image",img_bin); + cv::waitKey(0); + j=i+1; + while(!flag) + { + if (dist_sq(centroid[i], centroid[j]) < thresh_sq) + { + // lane1=lane1->next; + // lane1.x= &(centroid[j].x); + // lane1.y= &(centroid[j].y); + + flag++; + i=j; + } + else + j++; + } + + } + + // lane1->next=NULL; + int i=1; + flag=0; + for(;!flag;i++) + { + if(visited[(centroid[i]).y][(centroid[i]).x]!=1) + flag++; + } + i--; + + // lane2.x= ¢roid[i].x; + //lane2.y= ¢roid[i].y; + for(;i<=count;i++) + { val= visited[(centroid[i]).y][(centroid[i]).x]; + img_bin=colour(img_bin, val,2); + visited[(centroid[i]).y][(centroid[i]).x]=2; + j=i+1; + // cv::namedWindow("image",CV_WINDOW_AUTOSIZE); + cv::imshow("image",img_bin); + cv::waitKey(0); + + while(!flag) + { + if (dist_sq(centroid[i], centroid[j]) < thresh_sq) + { + // lane2=lane2->next; + // lane2.x= centroid[j].x; + // lane2.y= centroid[j].y; + + flag++; + i=j; + } + else + j++; + } + + } + // lane2->next=NULL; + return img_bin; +} + +int main(int argc, char* argv[]) +{ + cv::waitKey(0); + img_process img_p; + cv::Mat img,img_bin, img_lanes; + img_p.img= cv::imread(argv[1],3); + img_bin= cv::imread(argv[1],0); + img_bin= img_p.binary(img_bin,10); + cv::namedWindow("image",CV_WINDOW_AUTOSIZE); + cv::imshow("image",img_bin); + cv::waitKey(0); + img_p.bfs(img_bin); + img_p.centroid= new pos[img_p.count]; + for(int i=0;i