Exemplo n.º 1
0
QImage ImageFormat::MatGray2QImage(cv::Mat const& src) {
	 cv::Mat temp;
	 QImage dest((uchar*) src.data, src.cols, src.rows, src.step, QImage::Format_Indexed8);
	 QImage dest2(dest);
	 dest2.detach();
	 return dest2;
}
Exemplo n.º 2
0
void main()
{

    //构建数组
    Programmer vp[6] = {
        Programmer("Andrei", 6),
        Programmer("Stanley", 5),
        Programmer("Plaught", 4),
        Programmer("BillGates", 3),
        Programmer("Fowler", 2),
        Programmer("Meyes", 1)
    };
    //构建set
    std::set<Programmer, ProgrammerIdGreater > dest(vp, vp+6);

    //遍历set
    std::for_each( dest.begin(), dest.end(), std::mem_fun(&Programmer::Print) );

    //将dest中的BillGates改为David
    std::set<Programmer, ProgrammerIdGreater>::iterator it = dest.find(Programmer("BillGates", 3));
    if(it != dest.end())
        const_cast<Programmer&>(*it).SetName("David");

    //遍历set
    std::for_each( dest.begin(), dest.end(), std::mem_fun(&Programmer::Print) );

    //新set2用名字排序
    std::set<Programmer, ProgrammerNameComparer > dest2(dest, dest+6);

    //遍历set2
    std::for_each( dest2.begin(), dest2.end(), std::mem_fun(&Programmer::Print) );


}
Exemplo n.º 3
0
QImage ImageFormat::Mat2QImage(cv::Mat const& src) {
	 cv::Mat temp;
	 cvtColor(src, temp,CV_BGR2RGB); 
	 QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
	 QImage dest2(dest);
	 dest2.detach();
	 return dest2;
}
QImage BachelorThesis::mat2QImage( cv::Mat const& src )
{
	cv::Mat temp; // make the same cv::Mat
	cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
	QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
	QImage dest2(dest);
	dest2.detach(); // enforce deep copy
	return dest2;
}
Exemplo n.º 5
0
QImage ImgProc::toQImage(const cv::Mat &img)
{
    cv::Mat temp;
    cv::cvtColor(img, temp,CV_BGRA2RGBA);

    QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGBA8888);
    QImage dest2(dest);
    dest2.detach(); // enforce deep copy
    return dest2;
}
Exemplo n.º 6
0
void test_single_dest() {

   // push only
   tbb::flow::graph g;
   tbb::flow::source_node<T> src(g, source_body<T>() );
   test_push_receiver<T> dest;
   tbb::flow::make_edge( src, dest );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       ASSERT( dest.get_count(i) == 1, NULL ); 
   }

   // push only
   tbb::atomic<int> counters3[N];
   tbb::flow::source_node<T> src3(g, source_body<T>() );
   function_body<T> b3( counters3 );
   tbb::flow::function_node<T,bool> dest3(g, tbb::flow::unlimited, b3 );
   tbb::flow::make_edge( src3, dest3 );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       int v = counters3[i];
       ASSERT( v == 1, NULL ); 
   }

   // push & pull 
   tbb::flow::source_node<T> src2(g, source_body<T>() );
   tbb::atomic<int> counters2[N];
   function_body<T> b2( counters2 );
   tbb::flow::function_node<T,bool> dest2(g, tbb::flow::serial, b2 );
   tbb::flow::make_edge( src2, dest2 );
#if TBB_PREVIEW_FLOW_GRAPH_FEATURES
   ASSERT(src2.successor_count() == 1, NULL);
   typename tbb::flow::source_node<T>::successor_vector_type my_succs;
   src2.copy_successors(my_succs);
   ASSERT(my_succs.size() == 1, NULL);
#endif
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       int v = counters2[i];
       ASSERT( v == 1, NULL ); 
   }

   // test copy constructor
   tbb::flow::source_node<T> src_copy(src);
   test_push_receiver<T> dest_c;
   ASSERT( src_copy.register_successor(dest_c), NULL );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       ASSERT( dest_c.get_count(i) == 1, NULL ); 
   }
}
void exercise_constructor(unsigned int dim){
	std::cout << "Dimension " << dim << '\n';
	const size_t size=dim*dim;
	const double initVal=3.14;
	
	SU_vector source1(dim);
	source1.SetAllComponents(initVal);
	
	std::unique_ptr<double[]> buffer(new double[size]);
	for(unsigned int i=0; i<size; i++)
		buffer[i]=initVal;
	SU_vector source2(dim,buffer.get());
	
	std::cout << "Internal storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest1(source1);
	auto allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	auto components=dest1.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source1[0]=0;
	std::cout << "Memory aliasing: " << (dest1[0]==source1[0]) << '\n';
	
	std::cout << "External storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest2(source2);
	allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	components=dest2.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source2[0]=0;
	std::cout << "Memory aliasing: " << (dest2[0]==source2[0]) << '\n';
	std::cout << '\n';
}
Exemplo n.º 8
0
void test_single_dest() {

   // push only
   tbb::flow::graph g;
   tbb::flow::source_node<T> src(g, source_body<T>() );
   test_push_receiver<T> dest;
   tbb::flow::make_edge( src, dest );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       ASSERT( dest.get_count(i) == 1, NULL ); 
   }

   // push only
   tbb::atomic<int> counters3[N];
   tbb::flow::source_node<T> src3(g, source_body<T>() );
   function_body<T> b3( counters3 );
   tbb::flow::function_node<T,bool> dest3(g, tbb::flow::unlimited, b3 );
   tbb::flow::make_edge( src3, dest3 );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       int v = counters3[i];
       ASSERT( v == 1, NULL ); 
   }

   // push & pull 
   tbb::flow::source_node<T> src2(g, source_body<T>() );
   tbb::atomic<int> counters2[N];
   function_body<T> b2( counters2 );
   tbb::flow::function_node<T,bool> dest2(g, tbb::flow::serial, b2 );
   tbb::flow::make_edge( src2, dest2 );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       int v = counters2[i];
       ASSERT( v == 1, NULL ); 
   }

   // test copy constructor
   tbb::flow::source_node<T> src_copy(src);
   test_push_receiver<T> dest_c;
   ASSERT( src_copy.register_successor(dest_c), NULL );
   g.wait_for_all();
   for (int i = 0; i < N; ++i ) {
       ASSERT( dest_c.get_count(i) == 1, NULL ); 
   }
}
Exemplo n.º 9
0
QImage matToImage(cv::Mat const& src)
{
    cv::Mat temp;

    QImage::Format format;

    switch (src.type()) {
    case CV_32FC3:   // color with ranges: 0 ... 1
        src.convertTo(temp, CV_8UC3, 255.0, 0);
        cv::cvtColor(temp, temp, CV_BGR2RGB);
        format = QImage::Format_RGB888;
        break;
    case CV_32FC1:   // grayscale with ranges 0 ... 1
        src.convertTo(temp, CV_8UC1, 255.0, 0);
        format = QImage::Format_Indexed8;
        break;
    case CV_8UC1:   // grayscale with ranges 0 ... 255
        temp = src;
        format = QImage::Format_Indexed8;
        break;
    default:
        LWARNING << "Conversion not implemented.";
        return QImage();
    }

    // convert color from BGR to RGB
    cv::Mat temp2 = temp;
//    cv::cvtColor(temp, temp2, CV_BGR2RGB);

    QImage dest((uchar*) temp2.data, temp2.cols, temp2.rows, temp2.step, format);

    if (QImage::Format_Indexed8 == format) {
        // create palette
        for (int i = 0; i < 256; ++i) {
            dest.setColor(i, qRgb(i,i,i));
        }
    }

    QImage dest2(dest);
    dest2.detach(); // enforce deep copy
    return dest2;
}
Exemplo n.º 10
0
const bool FromUTF8(const std::vector<std::string::value_type> &utf8string, std::wstring &wcstring)
{
	if(utf8string.size()==0)
	{
		wcstring.assign(L"");
		return true;
	}

	std::vector<std::wstring::value_type> dest(utf8string.size(),0);		// dest will never be bigger than the input but could be smaller
	
	const UTF8 *sourcestart=reinterpret_cast<const UTF8 *>(&utf8string[0]);
	const UTF8 *sourceend=sourcestart+utf8string.size();
	
	if(sizeof(std::wstring::value_type)==2 && sizeof(UTF16)==2)
	{	
		UTF16 *deststart=reinterpret_cast<UTF16 *>(&dest[0]);
		UTF16 *destend=deststart+dest.size();
		
		ConversionResult rval=ConvertUTF8toUTF16(&sourcestart,sourceend,&deststart,destend,lenientConversion);
		
		if(rval!=conversionOK)
		{
			return false;	
		}
		
		wcstring.assign(dest.begin(),dest.end()-(destend-deststart));
		
	}
	else if(sizeof(std::wstring::value_type)==4 && sizeof(UTF32)==4)
	{
		UTF32 *deststart=reinterpret_cast<UTF32 *>(&dest[0]);
		UTF32 *destend=deststart+dest.size();
		
		ConversionResult rval=ConvertUTF8toUTF32(&sourcestart,sourceend,&deststart,destend,lenientConversion);

		if(rval!=conversionOK)
		{
			return false;
		}
		
		wcstring.assign(dest.begin(),dest.end()-(destend-deststart));
		
	}
	else
	{
		std::vector<UTF32> dest2(utf8string.size(),0);
		UTF32 *deststart=reinterpret_cast<UTF32 *>(&dest2[0]);
		UTF32 *destend=deststart+dest2.size();

		ConversionResult rval=ConvertUTF8toUTF32(&sourcestart,sourceend,&deststart,destend,lenientConversion);

		if(rval!=conversionOK)
		{
			return false;
		}

		wcstring.assign(dest2.begin(),dest2.end()-(destend-deststart));

	}

	return true;
}
Exemplo n.º 11
0
void LinkStatusWidget::paintEvent(QPaintEvent *event){

    initLines();

    QPainter painter(this);

    QPixmap pic(QString::fromUtf8(":/computer_white.png"));

    QRectF dest(0,0,pic.width(),pic.height());



    QPixmap pic2(QString::fromUtf8(":/honeywell.png"));

    QRectF dest2(0,0,pic2.width(),pic2.height());
    //220*180

    QRectF target_0(this->left_left,this->left_top,this->left_width,this->left_height);

    QRectF target_1(this->width()-this->right_right-this->right_width,this->right_top,this->right_width,this->right_height);

    QRectF target_2(this->width()-this->right_right-this->right_width,this->right_top+this->right_height+this->right_space,this->right_width,this->right_height);

    painter.setPen(Qt::white);
    painter.drawPixmap(target_0,pic2,dest2);

    painter.drawText(this->left_left+this->left_width+this->left_space,this->left_top+painter.fontMetrics().height(),Config::LINKSTATUS_LABEL.split("#").at(2));



    painter.drawPixmap(target_1,pic,dest);

    QString text=Config::LINKSTATUS_LABEL.split("#").at(0);
    int f_w=painter.fontMetrics().width(text);

    painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+painter.fontMetrics().height()+this->right_space,text);

    painter.drawPixmap(target_2,pic,dest);

    text=Config::LINKSTATUS_LABEL.split("#").at(1);
    f_w=painter.fontMetrics().width(text);


    painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+this->right_height+this->right_space*2+painter.fontMetrics().height(),text);



    //draw base line
    painter.save();
    //#353942
    QPen pen1(Qt::white,8,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    pen1.setColor(QColor(53, 57, 66));

    painter.setPen(pen1);
    painter.drawLines(lines);
    painter.restore();

    if(!this->isConn){
        return;
    }

    int centerHeight=this->right_top+this->right_height+this->right_space/2;

    QColor co1 =QColor(146, 196, 15) ;
    QColor co2 =QColor(0, 255, 0, 0);

    QColor co3 =QColor( 255,0, 0,200);
    QColor co4 =QColor( 255,0,0, 0);


    int mleft=this->width()-this->right_right-this->right_width-this->right_space-this->countMain;
    int mright=mleft+this->line_width_main;

    if(this->isBroken_1){

        QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight);
        linearGradient.setColorAt(0,co3);
        linearGradient.setColorAt(1,co4);

        QPen pen2(linearGradient,5);
        pen2.setCapStyle(Qt::RoundCap);
        painter.setPen(pen2);

    }else{

        QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight);
        linearGradient.setColorAt(0,co1);
        linearGradient.setColorAt(1,co2);

        QPen pen2(linearGradient,5);
        pen2.setCapStyle(Qt::RoundCap);
        painter.setPen(pen2);

    }

    painter.drawLine(mleft,centerHeight,mright,centerHeight);


    int sbottom= this->right_top+this->right_height/2+this->countSub;
    int stop= sbottom-this->line_width_sub;
    int sright=this->width()-this->right_right+this->right_space;

    //message 2
    if(this->isBroken_2){

        QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom);
        linearGradient2.setColorAt(0,co4);
        linearGradient2.setColorAt(1,co3);

        QPen pen3(linearGradient2,4);
        pen3.setCapStyle(Qt::RoundCap);
        painter.setPen(pen3);

    }else{


        QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom);
        linearGradient2.setColorAt(0,co2);
        linearGradient2.setColorAt(1,co1);

        QPen pen3(linearGradient2,4);
        pen3.setCapStyle(Qt::RoundCap);
        painter.setPen(pen3);


    }

    painter.drawLine(sright,stop,sright,sbottom);


}