diff --git a/arna/oops_assign/beginner_tutorials/CMakeLists.txt b/arna/oops_assign/beginner_tutorials/CMakeLists.txt new file mode 100644 index 0000000..b0bd611 --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.4.6) +include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) + +# Set the build type. Options are: +# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage +# Debug : w/ debug symbols, w/o optimization +# Release : w/o debug symbols, w/ optimization +# RelWithDebInfo : w/ debug symbols, w/ optimization +# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries +#set(ROS_BUILD_TYPE RelWithDebInfo) + +rosbuild_init() + +#set the default path for built executables to the "bin" directory +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +#set the default path for built libraries to the "lib" directory +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) + +#uncomment if you have defined messages +#rosbuild_genmsg() +#uncomment if you have defined services +#rosbuild_gensrv() + +#common commands for building c++ executables and libraries +#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) +#target_link_libraries(${PROJECT_NAME} another_library) +#rosbuild_add_boost_directories() +#rosbuild_link_boost(${PROJECT_NAME} thread) +#rosbuild_add_executable(example examples/example.cpp) +#target_link_libraries(example ${PROJECT_NAME}) +#rosbuild_add_executable(hello src/helloROS.cpp) +rosbuild_add_executable(game src/play.cpp) +#rosbuild_add_executable(image src/image_proc101.cpp) diff --git a/arna/oops_assign/beginner_tutorials/Makefile b/arna/oops_assign/beginner_tutorials/Makefile new file mode 100644 index 0000000..b75b928 --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/Makefile @@ -0,0 +1 @@ +include $(shell rospack find mk)/cmake.mk \ No newline at end of file diff --git a/arna/oops_assign/beginner_tutorials/bin/game b/arna/oops_assign/beginner_tutorials/bin/game new file mode 100755 index 0000000..0ec8afb Binary files /dev/null and b/arna/oops_assign/beginner_tutorials/bin/game differ diff --git a/arna/oops_assign/beginner_tutorials/bin/hello b/arna/oops_assign/beginner_tutorials/bin/hello new file mode 100755 index 0000000..9ab0298 Binary files /dev/null and b/arna/oops_assign/beginner_tutorials/bin/hello differ diff --git a/arna/oops_assign/beginner_tutorials/bin/image b/arna/oops_assign/beginner_tutorials/bin/image new file mode 100755 index 0000000..db61957 Binary files /dev/null and b/arna/oops_assign/beginner_tutorials/bin/image differ diff --git a/arna/oops_assign/beginner_tutorials/mainpage.dox b/arna/oops_assign/beginner_tutorials/mainpage.dox new file mode 100644 index 0000000..872299c --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/mainpage.dox @@ -0,0 +1,14 @@ +/** +\mainpage +\htmlinclude manifest.html + +\b beginner_tutorials + + + +--> + + +*/ diff --git a/arna/oops_assign/beginner_tutorials/manifest.xml b/arna/oops_assign/beginner_tutorials/manifest.xml new file mode 100644 index 0000000..0921b3b --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/manifest.xml @@ -0,0 +1,18 @@ + + + + beginner_tutorials + + + arna + BSD + + http://ros.org/wiki/beginner_tutorials + + + + + + + + diff --git a/arna/oops_assign/beginner_tutorials/src/Makefile b/arna/oops_assign/beginner_tutorials/src/Makefile new file mode 100644 index 0000000..e2fe339 --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/src/Makefile @@ -0,0 +1,9 @@ + +all: image run + +image: image_proc101.cpp + g++ -g $^ -o $@ -Wall `pkg-config opencv --cflags --libs` +run: + ./image +clean: + rm image diff --git a/arna/oops_assign/beginner_tutorials/src/a.out b/arna/oops_assign/beginner_tutorials/src/a.out new file mode 100755 index 0000000..34f5537 Binary files /dev/null and b/arna/oops_assign/beginner_tutorials/src/a.out differ diff --git a/arna/oops_assign/beginner_tutorials/src/event.h b/arna/oops_assign/beginner_tutorials/src/event.h new file mode 100644 index 0000000..b28dddf --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/src/event.h @@ -0,0 +1,16 @@ +#include +#include +#include "point.h" +#include "image_proc101.cpp" + +using namespace std; + +class evt: public pt{ +public:int score,dice,can_play; +evt(int a,int b): pt(a,b){ + score=0;can_play=0; +}; + +void score_update(image* img); +int detect_circle(image* img); +}; diff --git a/arna/oops_assign/beginner_tutorials/src/game.cpp b/arna/oops_assign/beginner_tutorials/src/game.cpp new file mode 100644 index 0000000..53a914f --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/src/game.cpp @@ -0,0 +1,14 @@ +#include +#include +#include "event.h" +using namespace std; + +class game: public pt{ +public: +int winner_score,winner_id; +game(int a,int b): pt(a, b){ + x=a;y=b; +winner_score=0;winner_id=0; +}; +}; + diff --git a/arna/oops_assign/beginner_tutorials/src/helloROS.cpp b/arna/oops_assign/beginner_tutorials/src/helloROS.cpp new file mode 100644 index 0000000..4645654 --- /dev/null +++ b/arna/oops_assign/beginner_tutorials/src/helloROS.cpp @@ -0,0 +1,7 @@ +#include +using namespace std; + +int main(){ +cout<<"Hello"< +#include +#include +#include +using namespace std; + +class image{ +public: +cv::Mat img; +int** A,mark,*count_x,*count_y; +image(int a){ +img=cv::imread("/home/arnatubai/Desktop/circles2.png",CV_LOAD_IMAGE_COLOR); +A=new int*[img.rows]; + for(int i=0;i +#include +#include +#include +#include "image.h" + +struct ind{int x;int y; +struct ind* next;}; +struct ind *front,*rear; + + +void enqueue(int x,int y){ +struct ind* n; +n=(struct ind*)malloc(sizeof(struct ind)); +n->x=x; +n->y=y; +n->next=NULL; +if(front==NULL){front=n;rear=front;} +else {rear->next=n;rear=n;} +} +void dequeue(){ + struct ind* t; + t=front; + front=t->next; + free(t); +} +void qfront(int* x,int *y){ + if(front!=NULL){ + *x=front->x; + *y=front->y;} + return; +} +int qempty(){ + if(front==NULL)return 1; + return 0;} + + + + +cv::Mat image:: game_binary(cv::Mat img){ + cv::Mat bin(img.rows,img.cols,CV_8UC1,cvScalarAll(0)); + // TODO : img.at(i, j)[0] = sdfsa +int i,j; +for(i=0;i(i, j)[0]>=235 || img.at(i, j)[1] >= 235|| img.at(i, j)[2] >= 235) + bin.at(i, j) = 255; + else bin.at(i, j) = 0; + } + +} +return bin; +} + + +//int* image:: allocate_centroid(int* ) + +cv::Mat image:: qblobdetect(cv::Mat& bin){ + //std::cout<<"hello"; + int i,j,x,y,wd=bin.cols,ht=bin.rows,max_pix_count=0,max_size_index=0; + //cout<<" a->"<(i,j)==255){ + if(A[i][j]==-1){ + mark=mark+1; + enqueue(i,j); + + //A[i][j]=0; + while(qempty()==0){ + qfront(&x,&y); + int k,l; + dequeue(); + for(k=x-1;k<=x+1;k++){ + for(l=y-1;l<=y+1;l++){ + if((k=0)&&(l>=0)&&(A[k][l]==-1) && bin.at(k,l)==255){ + enqueue(k,l); + A[k][l]=mark;} + }} + A[x][y]=mark; + } + //std::cout<<*mark<<" "<"<(i,j)[0]=qblob.at(i,j)[1]=qblob.at(i,j)[2]=255; + else{ + qblob.at(i,j)[0]=255*sin(A[i][j]); + qblob.at(i,j)[1]=255*cos(A[i][j]); + qblob.at(i,j)[2]=255*(sin(A[i][j])+cos(A[i][j]))/1.5; + } + }} + + //centroid(bin,A,*mark,count_x,count_y); + return qblob; +} + +void image:: centroid(cv::Mat qblob,int* count_pix){ + + for(int i=0;i<=mark;i++)count_pix[i]=0; + for(int i=0;i<=mark;i++)count_x[i]=0; + for(int i=0;i<=mark;i++)count_y[i]=0; + for(int i=0;iimg.rows<<","<img.cols<process_image(); +for(int i=1;i<=real->mark;i++){ + std::cout<count_x[i]<<","<count_y[i]< +#include "game.cpp" +#include +#include +#include + +using namespace std; + +pt:: pt(int a,int b){ +x=a; +y=b; +} + + +int evt::detect_circle(image* real){int present; + cout<<"starting pos="<=real->img.rows || y>=real->img.cols)return 0; +int i; +if(dice%2==0){ + present=real->A[x][y]; +for(i=present+1;i<=real->mark;i++){ + if(real->img.at(real->count_x[i],real->count_y[i])[2]==255){can_play=1;break;} + else can_play=0;}} +else if(dice==1){ + present=real->A[x][y]; +for(i=present+1;i<=real->mark;i++){ + if(real->img.at(real->count_x[i],real->count_y[i])[0]==255){can_play=1;break;} + else can_play=0;} +} +else{ + present=real->A[x][y]; +for(i=present+1;i<=real->mark;i++){ + if(real->img.at(real->count_x[i],real->count_y[i])[1]==255){can_play=1;break;} + else can_play=0;} +} +if(i>real->mark)can_play=0; +if(can_play){ +x=real->count_x[i];y=real->count_y[i];} +cout<<"present="<>n; +int t=n; //total players +cout<>E->dice; +cout<<"passing pos:-"<x<<","<y<score_update(real); +cout<<"at position:-"<x<<","<y<score=E->score; +//G1->x=E->x;G1->y=E->y; +}while(E->can_play); +cout<<"score= "<score<score>G->winner_score){ + G->winner_score=E->score;G->winner_id=t-n; //if player 1 and 2 have same score, player 1 is winner, not 2 (assumed for simplicity). +} +} +cout<<"WINNER is player "<winner_id<<" with score="<winner_score< +#include +using namespace std; + +class pt{ +public: +int x;int y; +int r,g,b; +public: pt(int a,int b); +}; diff --git a/arna/road/CMakeLists.txt b/arna/road/CMakeLists.txt new file mode 100644 index 0000000..f8f1c9c --- /dev/null +++ b/arna/road/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 2.4.6) +include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) + +# Set the build type. Options are: +# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage +# Debug : w/ debug symbols, w/o optimization +# Release : w/o debug symbols, w/ optimization +# RelWithDebInfo : w/ debug symbols, w/ optimization +# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries +#set(ROS_BUILD_TYPE RelWithDebInfo) + +rosbuild_init() + +#set the default path for built executables to the "bin" directory +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +#set the default path for built libraries to the "lib" directory +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) + +#uncomment if you have defined messages +#rosbuild_genmsg() +#uncomment if you have defined services +#rosbuild_gensrv() + +#common commands for building c++ executables and libraries +#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) +#target_link_libraries(${PROJECT_NAME} another_library) +#rosbuild_add_boost_directories() +#rosbuild_link_boost(${PROJECT_NAME} thread) +#rosbuild_add_executable(example examples/example.cpp) +#target_link_libraries(example ${PROJECT_NAME}) diff --git a/arna/road/Makefile b/arna/road/Makefile new file mode 100644 index 0000000..b75b928 --- /dev/null +++ b/arna/road/Makefile @@ -0,0 +1 @@ +include $(shell rospack find mk)/cmake.mk \ No newline at end of file diff --git a/arna/road/mainpage.dox b/arna/road/mainpage.dox new file mode 100644 index 0000000..e3254e1 --- /dev/null +++ b/arna/road/mainpage.dox @@ -0,0 +1,14 @@ +/** +\mainpage +\htmlinclude manifest.html + +\b road + + + +--> + + +*/ diff --git a/arna/road/manifest.xml b/arna/road/manifest.xml new file mode 100644 index 0000000..869f845 --- /dev/null +++ b/arna/road/manifest.xml @@ -0,0 +1,16 @@ + + + + road + + + arna + BSD + + http://ros.org/wiki/road + + + + + + diff --git a/arna/road/src/Makefile b/arna/road/src/Makefile new file mode 100644 index 0000000..28e4121 --- /dev/null +++ b/arna/road/src/Makefile @@ -0,0 +1,7 @@ +all: road + +road: road_identify.cpp + g++ -g $^ -o $@ -Wall `pkg-config opencv --cflags --libs` + + + diff --git a/arna/road/src/road b/arna/road/src/road new file mode 100755 index 0000000..9306f06 Binary files /dev/null and b/arna/road/src/road differ diff --git a/arna/road/src/road_identify.cpp b/arna/road/src/road_identify.cpp new file mode 100644 index 0000000..55ee04b --- /dev/null +++ b/arna/road/src/road_identify.cpp @@ -0,0 +1,358 @@ +#include +#include +#include +#include +#include + +const int threshold=125; + +class point{ +public: int x,y; +}; + +struct ind{int x;int y; +struct ind* next;}; +struct ind *front,*rear; + + +void enqueue(int x,int y){ +struct ind* n; +n=(struct ind*)malloc(sizeof(struct ind)); +n->x=x; +n->y=y; +n->next=NULL; +if(front==NULL){front=n;rear=front;} +else {rear->next=n;rear=n;} +} +void dequeue(){ + struct ind* t; + t=front; + front=t->next; + free(t); +} +void qfront(int* x,int *y){ + if(front!=NULL){ + *x=front->x; + *y=front->y;} + return; +} +int qempty(){ + if(front==NULL)return 1; + return 0;} + +float dist(point p1,point p2){ +return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)); +} + +struct poly{ + int degree; + float* coeff; +}; + +struct poly add(struct poly p1,struct poly p2){ + int n=p1.degree,m=p2.degree; +int ld=n>m?m:n; +struct poly p3; +p3.degree=n+m-ld; +p3.coeff=new float[p3.degree+1]; +for(int i=0;i<=ld;i++)p3.coeff[i]=p1.coeff[i]+p2.coeff[i]; +for(int i=ld+1;i<=p3.degree;i++){ + if(ld==n)p3.coeff[i]=p2.coeff[i]; + else p3.coeff[i]=p1.coeff[i];} +return p3;} + +struct poly mult(struct poly p1,struct poly p2){ + struct poly p3; + p3.degree=p1.degree+p2.degree; + p3.coeff=new float[p3.degree+1]; + for(int i=0;i<=p3.degree;i++)p3.coeff[i]=0; +for(int i=0;i<=p1.degree;i++){ + for(int j=0;j<=p2.degree;j++)p3.coeff[i+j]+=p1.coeff[i]*p2.coeff[j]; +} +return p3; +} + +struct poly langrange(point* P){ + struct poly p1,p2; + p1.degree=p2.degree=0; + p1.coeff=new float[1]; + p2.coeff=new float[1]; + p1.coeff[0]=1; + p2.coeff[0]=0; + for(int i=0;i<=5;i++){ + struct poly p3; + p3.degree=1; + p3.coeff=new float[2]; + p3.coeff[0]=1; + float denom=1; + for(int j=0;j<=5;j++){ + if(j!=i){denom*=(P[i].x-P[j].x); + p3.coeff[1]=-P[j].x; + p1=mult(p1,p3);} + } + denom/=P[i].y; + struct poly pt; + pt.degree=0; + pt.coeff=new float[1]; + if(denom!=0)pt.coeff[0]=1/denom; + else pt.coeff[0]=0; + p1=mult(p1,pt); + p2=add(p2,p1); + p1.degree=0; + p1.coeff=new float[1]; + p1.coeff[0]=1; + //std::cout<<"degree so far:"<"<(i,j)==255){ + if(A[i][j]==-1){ + *mark=*mark+1; + enqueue(i,j); + + //A[i][j]=0; + while(qempty()==0){ + qfront(&x,&y); + int k,l; + dequeue(); + for(k=x-1;k<=x+1;k++){ + for(l=y-1;l<=y+1;l++){ + if((k=0)&&(l>=0)&&(A[k][l]==-1) && bin.at(k,l)==255){ + enqueue(k,l); + A[k][l]=*mark;} + }} + A[x][y]=*mark; + } + //std::cout<<*mark<<" "<"<(i,j)[0]=qblob.at(i,j)[1]=qblob.at(i,j)[2]=255; + else{ + qblob.at(i,j)[0]=255*sin(A[i][j]); + qblob.at(i,j)[1]=255*cos(A[i][j]); + qblob.at(i,j)[2]=255*(sin(A[i][j])+cos(A[i][j]))/1.5; + } + }} + + //centroid(bin,A,*mark,count_x,count_y); + return qblob; +} + +cv::Mat game_binary(cv::Mat img){ + cv::Mat bin(img.rows,img.cols,CV_8UC1,cvScalarAll(0)); + // TODO : img.at(i, j)[0] = sdfsa +int i,j; +for(i=0;i(i, j)[0]>=235 || img.at(i, j)[1] >= 235|| img.at(i, j)[2] >= 235) + bin.at(i, j) = 255; + else bin.at(i, j) = 0; + } + +} +return bin; +} + + + +cv::Mat link_blobs(cv::Mat qblob,int** A,int mark,point* min_x,point* max_x,point* min_y,point* max_y,int* connected_index){ + for(int i=0;imax_x[r].x){max_x[r].x=i;max_x[r].y=j;} + if(imax_y[r].y){max_y[r].x=i;max_y[r].y=j;} + if(j(i,j)[0]=qblob.at(i,j)[1]=qblob.at(i,j)[2]=255; + else{ + linked.at(i,j)[0]=255*sin(connected_index[A[i][j]]); + linked.at(i,j)[1]=255*cos(connected_index[A[i][j]]); + linked.at(i,j)[2]=255*(sin(connected_index[A[i][j]])+cos(connected_index[A[i][j]]))/1.5; + } + } +} +return linked; + +} + +void equation(int mark,point* min_x,point* min_y,point* max_x,point* max_y,int* connected_index,struct poly* p_lane1,struct poly* p_lane2){ +int* connected_index2=new int[mark+1]; +struct poly p1,p2,p3,p4; +point* max_x_lane_eq,*min_x_lane_eq,*min_y_lane_eq,*max_y_lane_eq; + max_x_lane_eq=new point[6]; + max_y_lane_eq=new point[6]; + min_x_lane_eq=new point[6]; + min_y_lane_eq=new point[6]; +for(int i=0;i<=mark;i++)connected_index2[i]=connected_index[i]; +int all_zero=0; +do{int r; + all_zero=0; + p1.degree=p2.degree=p3.degree=p4.degree=0; +p1.coeff=new float[1]; +p2.coeff=new float[1]; +p3.coeff=new float[1]; +p4.coeff=new float[1]; +p1.coeff[0]=p2.coeff[0]=p3.coeff[0]=p4.coeff[0]=0; +for(int i=0;i<=mark;i++)if(connected_index2[i]!=0){all_zero=1;r=connected_index2[i];break;} + +if(all_zero){int lane_pt=0,interpolated=0; + for(int i=0;i<=mark;i++){ + if(connected_index2[i]==r){ + lane_pt++; + max_x_lane_eq[lane_pt%6]=max_x[i]; + max_y_lane_eq[lane_pt%6]=max_y[i]; + min_x_lane_eq[lane_pt%6]=min_x[i]; + min_y_lane_eq[lane_pt%6]=min_y[i]; +if(lane_pt==6){ + for(int j=0;j<=5;j++)std::cout<=6){interpolated++; + + p1=add(p1,langrange(max_x_lane_eq)); + p2=add(p2,langrange(max_y_lane_eq)); + p3=add(p3,langrange(min_x_lane_eq)); + p4=add(p4,langrange(min_y_lane_eq)); + } + connected_index2[i]=0;} +//std::cout<<"done interpolating till "<=0 && j=0 && k=0 && l