void test_common_unordered_and_associative_container(Container & c, Data & d) { typedef typename Container::size_type size_type; typedef typename Container::key_of_value key_of_value; typedef typename Container::iterator iterator; typedef typename Container::const_iterator const_iterator; { assert( d.size() > 2 ); c.clear(); typename Container::reference r = *d.begin(); c.insert(d.begin(), ++d.begin()); BOOST_TEST( &*c.iterator_to(*c.begin()) == &r ); BOOST_TEST( &*c.iterator_to(*c.cbegin()) == &r ); c.clear(); c.insert(d.begin(), d.end()); Container const &cc = c; for( typename Data::const_iterator di = d.begin(), de = d.end(); di != de; ++di ) { BOOST_TEST( cc.find(key_of_value()(*di)) != cc.end() ); std::pair<const_iterator, const_iterator> rdi = cc.equal_range(key_of_value()(*di)); BOOST_TEST(rdi.first != rdi.second); BOOST_TEST(size_type(boost::intrusive::iterator_distance(rdi.first, rdi.second)) == cc.count(key_of_value()(*di))); } for( iterator ci = c.begin(), ce = c.end(); ci != ce; ) { BOOST_TEST( c.find(key_of_value()(*ci)) != c.end() ); std::pair<iterator, iterator> rci = c.equal_range(key_of_value()(*ci)); BOOST_TEST(rci.first != rci.second); size_type const sc = c.count(key_of_value()(*ci)); BOOST_TEST(size_type(boost::intrusive::iterator_distance(rci.first, rci.second)) == sc); BOOST_TEST(sc == c.erase(key_of_value()(*ci))); ci = rci.second; } BOOST_TEST(c.empty()); } { c.clear(); c.insert(d.begin(), d.end()); typename Data::const_iterator db = d.begin(); typename Data::const_iterator da = db++; size_type old_size = c.size(); c.erase(key_of_value()(*da)); BOOST_TEST( c.size() == old_size-1 ); //This should erase nothing size_type second_erase = c.erase_and_dispose( key_of_value()(*da), detail::null_disposer() ); BOOST_TEST( second_erase == 0 ); BOOST_TEST( c.count(key_of_value()(*da)) == 0 ); BOOST_TEST( c.count(key_of_value()(*db)) != 0 ); BOOST_TEST( c.find(key_of_value()(*da)) == c.end() ); BOOST_TEST( c.find(key_of_value()(*db)) != c.end() ); BOOST_TEST( c.equal_range(key_of_value()(*db)).first != c.end() ); BOOST_TEST( c.equal_range(key_of_value()(*da)).first == c.equal_range(key_of_value()(*da)).second ); } { c.clear(); c.insert( d.begin(), d.end() ); size_type orig_size = c.size(); Container move_c(::boost::move(c)); BOOST_TEST(orig_size == move_c.size()); BOOST_TEST( c.empty()); for( typename Data::const_iterator di = d.begin(), de = d.end(); di != de; ++di ) { BOOST_TEST( move_c.find(key_of_value()(*di)) != move_c.end() ); } c = ::boost::move(move_c); for( typename Data::const_iterator di = d.begin(), de = d.end(); di != de; ++di ) { BOOST_TEST( c.find(key_of_value()(*di)) != c.end() ); } BOOST_TEST( move_c.empty()); } typedef detail::bool_<is_unordered<Container>::value> enabler; test_common_unordered_and_associative_container(c, d, enabler()); }
void test_sequence_container(Container & c, Data & d) { assert( d.size() > 2 ); { c.clear(); BOOST_TEST( c.size() == 0 ); BOOST_TEST( c.empty() ); { typename Data::iterator i = d.begin(); c.insert( c.begin(), *i ); BOOST_TEST( &*c.iterator_to(*c.begin()) == &*i ); BOOST_TEST( &*c.iterator_to(*c.cbegin()) == &*i ); BOOST_TEST( &*Container::s_iterator_to(*c.begin()) == &*i ); BOOST_TEST( &*Container::s_iterator_to(*c.cbegin()) == &*i ); c.insert( c.end(), *(++i) ); } BOOST_TEST( c.size() == 2 ); BOOST_TEST( !c.empty() ); typename Container::iterator i; i = c.erase( c.begin() ); BOOST_TEST( c.size() == 1 ); BOOST_TEST( !c.empty() ); i = c.erase( c.begin() ); BOOST_TEST( c.size() == 0 ); BOOST_TEST( c.empty() ); c.insert( c.begin(), *d.begin() ); BOOST_TEST( c.size() == 1 ); BOOST_TEST( !c.empty() ); { typename Data::iterator di = d.begin(); ++++di; c.insert( c.begin(), *(di) ); } i = c.erase( c.begin(), c.end() ); BOOST_TEST( i == c.end() ); BOOST_TEST( c.empty() ); c.insert( c.begin(), *d.begin() ); BOOST_TEST( c.size() == 1 ); BOOST_TEST( c.begin() != c.end() ); i = c.erase_and_dispose( c.begin(), detail::null_disposer() ); BOOST_TEST( i == c.begin() ); c.assign(d.begin(), d.end()); BOOST_TEST( c.size() == d.size() ); c.clear(); BOOST_TEST( c.size() == 0 ); BOOST_TEST( c.empty() ); } { c.clear(); c.insert( c.begin(), d.begin(), d.end() ); Container move_c(::boost::move(c)); BOOST_TEST( move_c.size() == d.size() ); BOOST_TEST( c.empty()); c = ::boost::move(move_c); BOOST_TEST( c.size() == d.size() ); BOOST_TEST( move_c.empty()); } }
int main(int argc, char** argv) { int i; int j; int Ymax = 235; int Ymin = 16; int row,col; int sum = 0; int id = 0; double temp; double Cx = 109.38; double Cy = 152.02; double theta = 2.53; double ecx = 1.60; double ecy = 2.41; double a = 25.39; double b = 14.03; double t; double lea = 0; imt_l* H; imt_l* y; imt_c* resultr; imt_c* resultg; imt_c* resultb; imt_c* bi_graph; imt_c* result; imt_c* h; linux_mem_init(); rgb_mt_t* image = imread(argv[1]); if(image == NULL) { exit(2); } row = image->r->row; col = image->r->col; H = create_zero_l(3,3); resultr = create_zero_c(row,col); resultg = create_zero_c(row,col); resultb = create_zero_c(row,col); y = create_zero_l(row,col); medfilt2(image->r,resultr); move_c(resultr,image->r); medfilt2(image->g,resultg); move_c(resultg,image->g); medfilt2(image->b,resultb); move_c(resultb,image->b); imshow("blur.bmp",image); set_pixel_l(H,1,1,65.4810/255); set_pixel_l(H,1,2,128.5530/255); set_pixel_l(H,1,3,24.9660/255); set_pixel_l(H,2,1,-37.7970/255); set_pixel_l(H,2,2,-74.2030/255); set_pixel_l(H,2,3,112.0000/255); set_pixel_l(H,3,1,112.0000/255); set_pixel_l(H,3,2,-93.7860/255); set_pixel_l(H,3,3,-18.2140/255); for(i = 1;i <= row;i ++) for(j = 1;j <= col;j ++) { temp = get_pixel_l(H,1,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,1,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,1,3) * (double)get_pixel_c(image->b,i,j) + 16; set_pixel_c(resultr,i,j,(unsigned char)temp); temp = get_pixel_l(H,2,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,2,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,2,3) * (double)get_pixel_c(image->b,i,j) + 128; set_pixel_c(resultg,i,j,(unsigned char)temp); temp = get_pixel_l(H,3,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,3,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,3,3) * (double)get_pixel_c(image->b,i,j) + 128; set_pixel_c(resultb,i,j,(unsigned char)temp); } clear(H); bi_graph = create_zero_c(row,col); for(i = 1;i <= row;i ++) for(j = 1;j <= col;j ++) { temp = cos(theta) * ((double)get_pixel_c(resultg,i,j) - Cx) + sin(theta) * ((double)get_pixel_c(resultb,i,j) - Cy); set_pixel_l(y,i,j,-sin(theta)*((double)get_pixel_c(resultg,i,j) - Cx) + cos(theta)*((double)get_pixel_c(resultb,i,j) - Cy)); lea = (temp - ecx) * (temp - ecx) / (a * a) + (get_pixel_l(y,i,j) - ecy) * (get_pixel_l(y,i,j) - ecy) / b / b; if(lea < 1.0) { set_pixel_c(bi_graph,i,j,255); } if(get_pixel_c(resultr,i,j) <= 80) { set_pixel_c(bi_graph,i,j,0); } } clear(resultr); clear(resultg); clear(resultb); image->r = bi_graph; image->g = bi_graph; image->b = bi_graph; imshow("bigraph.bmp",image); h = create_zero_c(3,3); set_pixel_c(h,1,1,255); set_pixel_c(h,1,2,255); set_pixel_c(h,1,3,255); set_pixel_c(h,2,1,255); set_pixel_c(h,2,2,255); set_pixel_c(h,2,3,255); set_pixel_c(h,3,1,255); set_pixel_c(h,3,2,255); set_pixel_c(h,3,3,255); result = imrode(bi_graph,h); move_c(result,bi_graph); clear(result); clear(h); h = create_zero_c(12,12); for(i = 1;i <= 12;i ++) for(j = 1;j <= 12;j ++) set_pixel_c(h,i,j,255); result = imdilate(bi_graph,h); move_c(result,bi_graph); clear(result); clear(h); bwareaopen(bi_graph,row * col / 10); for(i = 1;i <= row;i ++) { for(j = 1;j <= col;j ++) { if(get_pixel_c(bi_graph,i,j) == 0) set_pixel_c(bi_graph,i,j,255); else set_pixel_c(bi_graph,i,j,0); } } bwareaopen(bi_graph,row * col / 10); for(i = 1;i <= row;i ++) { for(j = 1;j <= col;j ++) { if(get_pixel_c(bi_graph,i,j) == 0) set_pixel_c(bi_graph,i,j,255); else set_pixel_c(bi_graph,i,j,0); } } result = focus(bi_graph); id = identifier(result); image->r = bi_graph; image->g = bi_graph; image->b = bi_graph; imshow("result.bmp",image); clear(bi_graph); image = imread(argv[1]); for(i = 1;i <= row;i ++) for(j = 1;j < col;j ++) { if(i <= l1 && i >= l0 && j <= n1 && j >= n0) { if(get_pixel_c(result,i - l0,j - n0) == 255) { sum ++; set_pixel_c(image->r,i,j,0); set_pixel_c(image->g,i,j,255); set_pixel_c(image->b,i,j,0); } } if(((j > n0 - 5 && j < n0 + 5) || (j < n1 + 5 && j > n1 - 5)) && ((i < l1 + 5 && i > l1 - 5) || (i > l0 - 5&& i < l0 + 5))) { set_pixel_c(image->r,i,j,255); set_pixel_c(image->g,i,j,0); set_pixel_c(image->b,i,j,0); } } imshow("focus.bmp",image); m_stat(); characteristic(); if(id == 0) { printf("Unknown\n"); } else if(id == 1) { printf("Rock!\n"); } else if(id == 2) { printf("Scissors!\n"); } else if(id == 3) { printf("Paper!\n"); } return 0; }