void Gui::setCamara(const colorspaces::Image& image, int id) { // Set image IplImage src; // conversión a IplImage src = image; colorspaces::ImageRGB8 img_rgb888(image); // conversion will happen if needed Glib::RefPtr<Gdk::Pixbuf> imgBuff = Gdk::Pixbuf::create_from_data((const guint8*) img_rgb888.data, Gdk::COLORSPACE_RGB, false, 8, img_rgb888.width, img_rgb888.height, img_rgb888.step); if (id == 1) { gtk_image1->clear(); gtk_image1->set(imgBuff); } else { gtk_image2->clear(); gtk_image2->set(imgBuff); } }
cv::Mat CameraUtils::getImageFromCameraProxy(jderobot::ImageDataPtr dataPtr) { cv::Mat outImage; colorspaces::Image::FormatPtr fmt; fmt = colorspaces::Image::Format::searchFormat(dataPtr->description->format); if (!fmt) throw "Format not supported"; if (dataPtr->description->format == colorspaces::ImageRGB8::FORMAT_RGB8_Z.get()->name || dataPtr->description->format == colorspaces::ImageRGB8::FORMAT_DEPTH8_16_Z.get()->name ) { size_t dest_len = dataPtr->description->width*dataPtr->description->height*3; size_t source_len = dataPtr->pixelData.size(); unsigned char* origin_buf = (uchar*) malloc(dest_len); int r = uncompress((Bytef *) origin_buf, (uLongf *) &dest_len, (const Bytef *) &(dataPtr->pixelData[0]), (uLong)source_len); if(r != Z_OK) { fprintf(stderr, "[CMPR] Error:\n"); switch(r) { case Z_MEM_ERROR: fprintf(stderr, "[CMPR] Error: Not enough memory to compress.\n"); break; case Z_BUF_ERROR: fprintf(stderr, "[CMPR] Error: Target buffer too small.\n"); break; case Z_STREAM_ERROR: // Invalid compression level fprintf(stderr, "[CMPR] Error: Invalid compression level.\n"); break; } } else { colorspaces::Image imageRGB(dataPtr->description->width,dataPtr->description->height,colorspaces::ImageRGB8::FORMAT_RGB8,&(origin_buf[0])); colorspaces::ImageRGB8 img_rgb888(imageRGB);//conversion will happen if needed cv::Mat(cvSize(img_rgb888.width,img_rgb888.height), CV_8UC3, img_rgb888.data).copyTo(outImage); img_rgb888.release(); } if (origin_buf) free(origin_buf); } else if (dataPtr->description->format == colorspaces::ImageRGB8::FORMAT_RGB8.get()->name || dataPtr->description->format == colorspaces::ImageRGB8::FORMAT_DEPTH8_16.get()->name ) { colorspaces::Image imageRGB(dataPtr->description->width,dataPtr->description->height,colorspaces::ImageRGB8::FORMAT_RGB8,&(dataPtr->pixelData[0])); colorspaces::ImageRGB8 img_rgb888(imageRGB);//conversion will happen if needed cv::Mat(cvSize(img_rgb888.width,img_rgb888.height), CV_8UC3, img_rgb888.data).copyTo(outImage); img_rgb888.release(); } else if (dataPtr->description->format == colorspaces::ImageGRAY8::FORMAT_GRAY8_Z.get()->name) { //gay compressed size_t dest_len = dataPtr->description->width*dataPtr->description->height; size_t source_len = dataPtr->pixelData.size(); unsigned char* origin_buf = (uchar*) malloc(dest_len); int r = uncompress((Bytef *) origin_buf, (uLongf *) &dest_len, (const Bytef *) &(dataPtr->pixelData[0]), (uLong)source_len); if(r != Z_OK) { fprintf(stderr, "[CMPR] Error:\n"); switch(r) { case Z_MEM_ERROR: fprintf(stderr, "[CMPR] Error: Not enough memory to compress.\n"); break; case Z_BUF_ERROR: fprintf(stderr, "[CMPR] Error: Target buffer too small.\n"); break; case Z_STREAM_ERROR: // Invalid compression level fprintf(stderr, "[CMPR] Error: Invalid compression level.\n"); break; } } else { colorspaces::Image imageGray(dataPtr->description->width,dataPtr->description->height,colorspaces::ImageGRAY8::FORMAT_GRAY8,&(origin_buf[0])); colorspaces::ImageGRAY8 img_gray8(imageGray);//conversion will happen if needed cv::Mat(cvSize(img_gray8.width,img_gray8.height), CV_8UC1, img_gray8.data).copyTo(outImage); img_gray8.release(); } if (origin_buf) free(origin_buf); } else if (dataPtr->description->format == colorspaces::ImageGRAY8::FORMAT_GRAY8.get()->name){ colorspaces::Image imageGray(dataPtr->description->width,dataPtr->description->height,colorspaces::ImageGRAY8::FORMAT_GRAY8,&(dataPtr->pixelData[0])); colorspaces::ImageGRAY8 img_gray8(imageGray);//conversion will happen if needed cv::Mat(cvSize(img_gray8.width,img_gray8.height), CV_8UC1, img_gray8.data).copyTo(outImage); img_gray8.release(); } else{ LOG(ERROR) << "Unkown image format"; } return outImage; }