コード例 #1
0
ファイル: camera.cpp プロジェクト: STMPNGRND/rospilot
    bool sendPreview()
    {
        if(camera != nullptr && camera->getLiveImage(&image)) {
            bool keyFrame = false;
            bool transcodedSuccessfully = false;
            imagePub.publish(image);
            jpegDecoder->decodeInPlace(&image);
            liveStream->addFrame(&image);
            recorder->addFrame(&image);
            if (detector != nullptr) {
                detector->addFrame(&image);
            }

            return true;
        }
        return false;
    }
コード例 #2
0
ファイル: net_web_pframe.cpp プロジェクト: ADTL/stm32plus
    void showPicture(const std::string& uri) {

      // fade down the backlight to 10%, 4ms per step

      _backlight->fadeTo(10,4);

      // clear the screen

      _tft->setBackground(ColourNames::BLACK);
      _tft->clearScreen();

      // we're using a custom TCP client connection that processes incoming data on the receive IRQ
      // so that we avoid advertising a zero receive window back to the server with the performance
      // hit that we would take

      MyTcpClientConnection *conn;

      if(!_net->tcpConnect<MyTcpClientConnection>(_serverAddress,WEB_SERVER_PORT,conn))
        error("Failed to connect to web server");

      // manage the connection pointer in a scoped_ptr so it's automatically deleted (and closed)
      // when it goes out of scope

      HttpClient httpClient(*conn);

      // set the parameters for the HTTP GET

      httpClient.setUri(uri);
      httpClient.setHost(WEB_SERVER);
      httpClient.setVersion(HttpVersion::HTTP_1_0);       // connection to close after we get the image

      if(!httpClient.sendRequest()) {
        delete conn;
        error("Failed to send the request to the server");
      }

      // use a read-ahead input stream wrapped around a TCP input stream
      // with a read-ahead buffer of 256 bytes

      TcpInputStream tcis(*conn);

      // if the JPEG will fit then display it centered on screen, otherwise ignore it

      Size size;
      JpegDecoder<LcdPanel> jpeg;

      if(!jpeg.beginDecode(tcis,size)) {
        delete conn;
        error("Failed to decode JPEG image");
      }

      if(size.Height<=_tft->getHeight() && size.Width<=_tft->getWidth()) {

        // it fits, stream it in

        Point pt;

        pt.X=(_tft->getWidth()-size.Width)/2;
        pt.Y=(_tft->getHeight()-size.Height)/2;

        jpeg.endDecode(pt,*_tft);
      }

      delete conn;

      // fade up the backklight to 100%, 4ms per step

      _backlight->fadeTo(100,4);
    }
コード例 #3
0
ファイル: jpeg_benchmark.cpp プロジェクト: STMPNGRND/rospilot
int main(int argc, char **argv)
{
    // XXX: Assumes that the input image 1600x1200
    PixelFormat pixelFormat = PIX_FMT_YUV420P;
    JpegDecoder *jpegDecoder = new FFmpegJpegDecoder(1600, 1200, pixelFormat);

    sensor_msgs::CompressedImage image;
    image.format = "jpeg";

    std::string path(argv[1]);
    std::fstream f(path, std::ifstream::binary | std::ios_base::in);
    if (!f) {
        std::cout << "Failed to open " << path << std::endl;
        return 1;
    }
    f.seekg(0, f.end);
    int length = f.tellg();
    f.seekg(0, f.beg);
    char *buffer = new char[length];
    f.read(buffer, length);
    f.close();
    for (int i = 0; i < length; i++) {
        image.data.push_back(buffer[i]);
    }
    delete buffer;

    sensor_msgs::CompressedImage images[10];
    for (int i = 0; i < 10; i++) {
        images[i] = image;
    }

    int junk = 0;
    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
    for (int i = 0; i < 10; i++) {
        jpegDecoder->decodeInPlace(&images[i]);
        // Make sure there's a side effect
        junk += images[i].data.size();
    }
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
    double us = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000000.0;
    std::cout << "FFmpeg FPS " << 10 / us << std::endl;
    std::cout << "check: " << junk << std::endl;
    
    delete jpegDecoder;
    jpegDecoder = new TurboJpegDecoder(1600, 1200, pixelFormat);
    for (int i = 0; i < 10; i++) {
        images[i] = image;
    }
    junk = 0;
    start = std::chrono::steady_clock::now();
    for (int i = 0; i < 10; i++) {
        jpegDecoder->decodeInPlace(&images[i]);
        // Make sure there's a side effect
        junk += images[i].data.size();
    }
    end = std::chrono::steady_clock::now();
    us = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000000.0;
    std::cout << "TurboJpeg FPS " << 10 / us << std::endl;
    std::cout << "check: " << junk << std::endl;

    delete jpegDecoder;
    return 0;
}
コード例 #4
0
ファイル: processthread.cpp プロジェクト: SorcererX/SepiaCore
void ProcessThread::own_thread()
{
    enum class Format { UNKNOWN, RAW8, RAW16, MJPEG, YUYV, BGR8 };

    Format format = Format::UNKNOWN;
    int cv_format = CV_MAKETYPE( CV_8U, 1 );

    sepia::Stream::image_header_t* hdr = m_input->getHeader( m_id );
    switch( hdr->fourcc )
    {
    case 0x00000000:
        if( hdr->bpp == 8 )
        {
            format = Format::RAW8;
            cv_format = CV_MAKETYPE( CV_8U, 1 );
        }
        else if( hdr->bpp == 16 )
        {
            format = Format::RAW16;
            cv_format = CV_MAKETYPE( CV_16U, 1 );
        }
        else if( hdr->bpp == 24 )
        {
            format = Format::BGR8;
            cv_format = CV_MAKETYPE( CV_8U, 3 );
        }
        break;
    case FOURCC( 'M', 'J', 'P', 'G'):
        format = Format::MJPEG;
        cv_format = CV_MAKETYPE( CV_8U, 3 ); // format after conversion
        break;
    default:
        break;
    }

    cv::Mat input_frame( m_input->getHeader( m_id )->height, m_input->getHeader( m_id )->width, cv_format, m_input->getAddress( m_id ) );

    cv::Mat converted_frame( m_output->getHeader( m_id )->height, m_output->getHeader( m_id )->width, CV_8UC3 );

    if( m_rectifier == NULL )
    {
        converted_frame.data = reinterpret_cast< unsigned char* >( m_output->getAddress( m_id ) );
    }

    cv::Mat rectified_frame( m_output->getHeader( m_id )->height, m_output->getHeader( m_id )->width, CV_8UC3, m_output->getAddress( m_id ) );

    JpegDecoder decoder;

    while( !m_terminate )
    {
        if( format == Format::RAW8 || format == Format::RAW16 )
        {
            cv::demosaicing( input_frame, converted_frame, cv::COLOR_BayerBG2BGR_EA );
        }
        else if( format == Format::MJPEG )
        {
            // perform JPEG decode here
            decoder.readHeader( reinterpret_cast< unsigned char* >( input_frame.data ), m_input->getHeader( m_id )->size );
            decoder.readData( reinterpret_cast< unsigned char* >( converted_frame.data ), m_input->getHeader( m_id )->width * 3, true );
        }
        else {

        }

        if( m_rectifier != NULL )
        {
            if( m_id == 0 )
            {
                m_rectifier->remapLeft( &converted_frame, &rectified_frame );
            }
            else if( m_id == 1 )
            {
                m_rectifier->remapRight( &converted_frame, &rectified_frame );
            }
        }

        m_barrier->wait();
        if( m_id == 0 )
        {
            m_output->update();
            m_input->update();
        }
        m_barrier->wait();
        input_frame.data = reinterpret_cast< unsigned char* >( m_input->getAddress( m_id ) );

        if( m_rectifier != NULL )
        {
            rectified_frame.data = reinterpret_cast< unsigned char* >( m_output->getAddress( m_id ) );
        }
        else
        {
            converted_frame.data = reinterpret_cast< unsigned char* >( m_output->getAddress( m_id ) );
        }
    }
}
コード例 #5
0
ファイル: cv239.cpp プロジェクト: unix8net/jpegReadOfOpencv
int main()
{
	clock_t start, end;
	start = clock();
	JpegDecoder jpegDector;
	jpegDector.setSource("21.jpg");
	jpegDector.readHeader();
	int height = jpegDector.height();
	int width = jpegDector.width();
	cout<<"高为:"<<height<<"   宽为:"<<width<<endl;
	cout<<"通道数:"<<CV_MAT_CN(jpegDector.type())<<endl;
	cout<<"sign:"<<jpegDector.signature()<<endl;
	
	CvMat *mat = cvCreateMat(jpegDector.height(), jpegDector.width(),(jpegDector.type()));
	jpegDector.readData(*mat);
	end = clock();
	printf("Run time:%f ",(double)(end - start) );
#if 0
	unsigned char * data;
	for(int i=0;i<10;i++)
	{
		data = (uchar*)(mat->data.ptr + i*mat->step);
		for(int j=0;j<10;j++)
		{
			printf("%d ",data[j*3]);
			printf("%d ",data[j*3+1]);
			printf("%d   ",data[j*3+2]);
		}
		printf("\n");
	}
#endif
	printf("------cvMat-------\n\n");
	cvReleaseMat(&mat);
	//CvMat * imgSrc = cvLoadImageM("1.jpg");
#if 0
	IplImage *imgSrc = cvLoadImage("21.jpg");
	IplImage *imgRes = cvCreateImage(cvGetSize(imgSrc),8,3);
	
	cout<<imgSrc->nChannels<<"  "<<imgSrc->depth<<endl;
	//IplImage *imgRes = cvCreateImageHeader(cvGetSize(imgSrc),8,3);
	//cvNamedWindow("test source", CV_WINDOW_AUTOSIZE);
	cvShowImage("source", imgSrc);
	end = clock();
	//cvNamedWindow("test result", CV_WINDOW_AUTOSIZE);
	cvShowImage("result", imgRes);
#endif	
	//printf("Run time:%f ",(double)(end - start) );
	//cvWaitKey(0);
	system("pause");
}