void SnapWidget::mousePressEvent(QMouseEvent *mouse) { globalPressedPos=mouse->globalPos(); widgetPressedPos=mouse->pos(); if(mouse->buttons()==Qt::LeftButton)//只按下左键的情况 { int id=toolBar.getShapeActionID(); if(id==0) { setCursor(Qt::SizeAllCursor); } else { setCursor(Qt::CrossCursor); editing=true; switch(id) { case 1: painterPath.moveTo(widgetPressedPos); update(); break; case 5: fillImage(snapImage,mouse->pos(),toolBar.getBrush().color().rgb()); update(); break; case 6: visibleTextBorder=true; break; default:; } } } }
void UsbCam::grab_image(sensor_msgs::Image* msg) { // grab the image image_ = (camera_image_t *)calloc(1, sizeof(camera_image_t)); image_->width = RAW_IMAGE_WIDTH; image_->height = RAW_IMAGE_HEIGHT; image_->bytes_per_pixel = 3; image_->image_size = RAW_IMAGE_HEIGHT*RAW_IMAGE_WIDTH*3; image_->is_new = 0; image_->image = (char *)calloc(image_->image_size, sizeof(char)); memset(image_->image, 0, image_->image_size * sizeof(char)); grab_image(); // stamp the image msg->header.stamp = ros::Time::now(); // fill the info //if (monochrome_) //{ // fillImage(*msg, "mono8", image_->height, image_->width, image_->width, // image_->image); //} //else //{ fillImage(*msg, "rgb8", image_->height, image_->width, 3 * image_->width, image_->image); //} }
void DriverNodelet::publishRgbImage(const ImageBuffer& image, ros::Time time) const { sensor_msgs::ImagePtr rgb_msg = boost::make_shared<sensor_msgs::Image >(); rgb_msg->header.stamp = time; rgb_msg->header.frame_id = rgb_frame_id_; rgb_msg->height = image.metadata.height; rgb_msg->width = image.metadata.width; switch(image.metadata.video_format) { case FREENECT_VIDEO_RGB: rgb_msg->encoding = sensor_msgs::image_encodings::RGB8; rgb_msg->step = rgb_msg->width * 3; break; case FREENECT_VIDEO_BAYER: rgb_msg->encoding = sensor_msgs::image_encodings::BAYER_GRBG8; rgb_msg->step = rgb_msg->width; break; case FREENECT_VIDEO_YUV_RGB: rgb_msg->encoding = sensor_msgs::image_encodings::YUV422; rgb_msg->step = rgb_msg->width * 2; break; default: NODELET_ERROR("Unknown RGB image format received from libfreenect"); // Unknown encoding -- don't publish return; } rgb_msg->data.resize(rgb_msg->height * rgb_msg->step); fillImage(image, reinterpret_cast<void*>(&rgb_msg->data[0])); pub_rgb_.publish(rgb_msg, getRgbCameraInfo(image, time)); if (enable_rgb_diagnostics_) pub_rgb_freq_->tick(); }
RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float tStart, float dt, const bool omp) : ImageMOOs(w, h), _omp ( omp ) { this->t = tStart; this->dt = dt; fillImage(tStart); }
QImage QGLPixmapData::toImage() const { if (!isValid()) return QImage(); if (m_renderFbo) { copyBackFromRenderFbo(true); } else if (!m_source.isNull()) { // QVolatileImage::toImage() will make a copy always so no check // for active painting is needed. QImage img = m_source.toImage(); if (img.format() == QImage::Format_MonoLSB) { img.setColorCount(2); img.setColor(0, QColor(Qt::color0).rgba()); img.setColor(1, QColor(Qt::color1).rgba()); } return img; } else if (m_dirty || m_hasFillColor) { return fillImage(m_fillColor); } else { ensureCreated(); } QGLShareContextScope ctx(qt_gl_share_widget()->context()); glBindTexture(GL_TEXTURE_2D, m_texture.id); return qt_gl_read_texture(QSize(w, h), true, true); }
QImage QGLPixmapData::toImage() const { if (!isValid()) return QImage(); if (m_renderFbo) { copyBackFromRenderFbo(true); } else if (!m_source.isNull()) { QImageData *data = const_cast<QImage &>(m_source).data_ptr(); if (data->paintEngine && data->paintEngine->isActive() && data->paintEngine->paintDevice() == &m_source) { return m_source.copy(); } return m_source; } else if (m_dirty || m_hasFillColor) { return fillImage(m_fillColor); } else { ensureCreated(); } QGLShareContextScope ctx(qt_gl_share_context()); glBindTexture(GL_TEXTURE_2D, m_texture.id); return qt_gl_read_texture(QSize(w, h), true, true); }
int main(int argc, char **argv) { ros::init(argc, argv, "image_raw"); ros::NodeHandle n; image_transport::Publisher image_pub; image_transport::ImageTransport it(n); image_pub = it.advertise("image_raw", 1); sensor_msgs::Image img_; ros::Rate loop_rate(10); PixyCam cam; boost::thread workerThread(&PixyCam::run, &cam); // cam.run(); int count = 0; while (ros::ok()){ cv::Mat frame = cam.getImage(); fillImage(img_, "bgr8", frame.rows, frame.cols, frame.channels() * frame.cols, frame.data); image_pub.publish(img_); ros::spinOnce(); loop_rate.sleep(); ++count; } return 0; }
int main(int argc, char **argv) { ros::init(argc, argv, "image"); ros::NodeHandle n; image_transport::Publisher image_pub; image_transport::Publisher image_pub_compress; image_transport::ImageTransport it(n); image_pub = it.advertise("image_raw", 1); image_pub_compress = it.advertise("image_raw_compress", 1); sensor_msgs::Image img_; sensor_msgs::Image img_compress_; ros::Rate loop_rate(25); cv::Mat frame; cv::VideoCapture cap(0); std::vector<int> params; std::vector<uchar> buf; params.push_back(CV_IMWRITE_JPEG_QUALITY); params.push_back(25); //image quality while (ros::ok()){ cap>> frame; fillImage(img_, "bgr8", frame.rows, frame.cols, frame.channels() * frame.cols, frame.data); cv::imencode(".jpg", frame, buf, params); cv::Mat frame_compress(buf); fillImage(img_compress_, "mono8", frame_compress.rows, frame_compress.cols, frame_compress.channels()* frame_compress.cols, frame_compress.data); image_pub.publish(img_); image_pub_compress.publish(img_compress_); ros::spinOnce(); loop_rate.sleep(); } return 0; }
/**************************************************************** * Generate Maze ****************************************************************/ void PhotoMaze :: huntAndKill(){ Vec2D<int> startPos((int)(ofRandom(1)*rw), (int)(ofRandom(1)*rh)); while (startPos.x != -1) { rWalk(startPos); startPos = hunt(); } fillImage(); }
void Sprite::clear() { if (!exists()) return; fillImage(0, ImgConv.convertColor(0, _palette)); memset(_transparencyMap, 1, _surfacePaletted.w * _surfacePaletted.h); }
void Sprite::darken() { if (!exists()) return; fillImage(0, ImgConv.getColor(0, 0, 0)); memset(_transparencyMap, 0, _surfacePaletted.w * _surfacePaletted.h); }
void Sprite::fill(byte c) { if (!exists()) return; fillImage(c, ImgConv.convertColor(c, _palette)); memset(_transparencyMap, 0, _surfacePaletted.w * _surfacePaletted.h); }
void Sprite::shade(uint32 c) { if (!exists()) return; fillImage(0, c); memset(_transparencyMap, 2, _surfacePaletted.w * _surfacePaletted.h); }
QImage QEglGLPixmapData::toImage() const { TRACE(); // We should not do so many toImage calls alltogether. This is what is slowing us down right now. // QWK should keep a cache of transformed images instead of re-doing it every frame. // FIXME make QWebKit not do so many QPixmap(QImage(pixmap.toImage).transform()) style transformations. if (!isValid()) return QImage(); if (!m_source.isNull()) { return m_source; } else if (m_dirty || m_hasFillColor) { m_source = fillImage(m_fillColor); return m_source; } else { ensureCreated(); } // read the image from the FBO to memory if(m_fbo) { // we read the data back from the fbo m_ctx->makeCurrent(); QGLShareContextScope ctx(qt_gl_share_widget()->context()); glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo); // this does glReadPixels - not very fast! QImage temp=qt_gl_read_framebuffer(QSize(w, h), true, true); glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); m_source=temp; m_ctx->doneCurrent(); return temp; } else if (m_texture.id) { // we read back from the texture by binding its id as a framebuffer // is this in the OpenGL standard? It seems to work m_ctx->makeCurrent(); QGLShareContextScope ctx(qt_gl_share_widget()->context()); glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_texture.id); // this does glReadPixels - not very fast QImage temp=qt_gl_read_framebuffer(QSize(w, h), true, true); glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); // should we cache the fetched image locally to speed up future access? // m_source=temp; m_ctx->doneCurrent(); return temp; } else { QImage temp(w,h, QImage::Format_ARGB32_Premultiplied); // FIXME indicating something went wrong, neither of above cases worked - look out for yellow images temp.fill(Qt::yellow); m_source=temp; return temp; } }
bool take_and_send_image() { usb_cam_camera_grab_image(camera_image_); fillImage(img_, "rgb8", camera_image_->height, camera_image_->width, 3 * camera_image_->width, camera_image_->image); img_.header.stamp = ros::Time::now(); sensor_msgs::CameraInfoPtr ci(new sensor_msgs::CameraInfo(cinfo_->getCameraInfo())); ci->header.frame_id = img_.header.frame_id; ci->header.stamp = img_.header.stamp; image_pub_.publish(img_, *ci); return true; }
void HeaterMOO::animationStep ( bool& isNeedUpdateView ) { for ( int i = 0; i < _blindItr; i++ ) { diffuse ( _imgA, _imgB ); erase ( _imgHeater, _imgB ); double** tmp = _imgA; // swapping _imgA = _imgB; _imgB = tmp; } fillImage ( _imgA ); isNeedUpdateView = true; // A devient B, B devient A // tester a chaque fois isNeedUpdateView pour faire en sorte qu'il update une fois sur blindItr! }
bool Simple::prepareMaterial() { for (auto entry : mTerrainPageSurfaces) { auto surfaceLayer = entry.second; if (surfaceLayer != mTerrainPageSurfaces.begin()->second) { if (surfaceLayer->intersects(*mGeometry)) { mLayers.emplace_back(Layer { *surfaceLayer, new OgreImage(new Image::ImageBuffer(mPage.getBlendMapSize(), 1)) }); OgreImage* image = mLayers.back().blendMap; image->reset(); surfaceLayer->fillImage(*mGeometry, *image, 0); } } } return true; }
void imageCallback(const sensor_msgs::ImageConstPtr& msg) { char* img_mono8 = new char[msg->height*msg->width]; float* img_32FC1 = new float[msg->height*msg->width]; memcpy(img_32FC1,&msg->data[0],sizeof(float)*msg->height*msg->width); // change disp to depth for(int i = 0 ; i < msg->height; i++) { for(int j = 0; j<msg->width; j++) { float data_tmp = img_32FC1[i*msg->width + j] > MAX_DEPTH ? MAX_DEPTH : img_32FC1[i*msg->width + j]; if (data_tmp == 0){ data_tmp = MAX_DEPTH; } else{ data_tmp = data_tmp < MIN_DEPTH ? MIN_DEPTH : data_tmp; } img_mono8[i*msg->width + j] = ( unsigned char )255 * (1.0 - (data_tmp - MIN_DEPTH)/(MAX_DEPTH - MIN_DEPTH)); } } fillImage(img_depth, "mono8", msg->height, msg->width, msg->width, img_mono8); delete[] img_mono8; delete[] img_32FC1; // Convert to OpenCV native BGR color try { g_last_image = cv_bridge::toCvCopy(img_depth,"mono8")->image; } catch (cv_bridge::Exception& e) { ROS_ERROR( "Unable to convert '%s' image for display: '%s'", msg->encoding.c_str(), e.what()); } if (!g_last_image.empty()) { const cv::Mat &image = g_last_image; cv::imshow(g_window_name, image); cv::waitKey(3); } }
TEST_C(NodeRemovalTest, pixelsAreUpdatedWhenNodeIsRemoved) { DummyMinMaxTreeImageType image(2, 2); auto levelHeights = makeLevelHeights({ 3018, 91314 }); auto lowerPixelColor = levelHeights[0]; auto higherPixelColor = levelHeights[1]; fillImage(image, higherPixelColor); image.setPixel(0, 0, lowerPixelColor); assignPixelsToLatestNodes(image); auto& higherNode = image.getPixelNode(1, 1); image.removeNode(higherNode); verifyFilledImagePixels(image, lowerPixelColor); }
void DriverNodelet::publishIrImage(const ImageBuffer& ir, ros::Time time) const { sensor_msgs::ImagePtr ir_msg = boost::make_shared<sensor_msgs::Image>(); ir_msg->header.stamp = time; ir_msg->header.frame_id = depth_frame_id_; ir_msg->encoding = sensor_msgs::image_encodings::MONO16; ir_msg->height = ir.metadata.height; ir_msg->width = ir.metadata.width; ir_msg->step = ir_msg->width * sizeof(uint16_t); ir_msg->data.resize(ir_msg->height * ir_msg->step); fillImage(ir, reinterpret_cast<void*>(&ir_msg->data[0])); pub_ir_.publish(ir_msg, getIrCameraInfo(ir, time)); if (enable_ir_diagnostics_) pub_ir_freq_->tick(); }
QImage QGLPixmapData::toImage() const { if (!isValid()) return QImage(); if (m_renderFbo) { copyBackFromRenderFbo(true); } else if (!m_source.isNull()) { return m_source; } else if (m_dirty || m_hasFillColor) { return fillImage(m_fillColor); } else { ensureCreated(); } QGLShareContextScope ctx(qt_gl_share_widget()->context()); glBindTexture(GL_TEXTURE_2D, m_texture.id); return qt_gl_read_texture(QSize(w, h), true, true); }
void DriverNodelet::publishDepthImage(const ImageBuffer& depth, ros::Time time) const { bool registered = depth.is_registered; sensor_msgs::ImagePtr depth_msg = boost::make_shared<sensor_msgs::Image>(); depth_msg->header.stamp = time; depth_msg->encoding = sensor_msgs::image_encodings::TYPE_16UC1; depth_msg->height = depth.metadata.height; depth_msg->width = depth.metadata.width; depth_msg->step = depth_msg->width * sizeof(short); depth_msg->data.resize(depth_msg->height * depth_msg->step); fillImage(depth, reinterpret_cast<void*>(&depth_msg->data[0])); if (z_offset_mm_ != 0) { uint16_t* data = reinterpret_cast<uint16_t*>(&depth_msg->data[0]); for (unsigned int i = 0; i < depth_msg->width * depth_msg->height; ++i) if (data[i] != 0) data[i] += z_offset_mm_; } if (registered) { // Publish RGB camera info and raw depth image to depth_registered/ ns depth_msg->header.frame_id = rgb_frame_id_; pub_depth_registered_.publish(depth_msg, getRgbCameraInfo(depth, time)); } else { // Publish depth camera info and raw depth image to depth/ ns depth_msg->header.frame_id = depth_frame_id_; pub_depth_.publish(depth_msg, getDepthCameraInfo(depth, time)); } if (enable_depth_diagnostics_) pub_depth_freq_->tick(); // Projector "info" probably only useful for working with disparity images if (pub_projector_info_.getNumSubscribers() > 0) { pub_projector_info_.publish(getProjectorCameraInfo(depth, time)); } }
void HeaterMOO::initImages () { int h = getH (); int w = getW (); alloc ( _imgHeater, w, h ); alloc ( _imgInit, w, h ); alloc ( _imgA, w, h ); alloc ( _imgB, w, h ); init ( _imgHeater, w, h, .0 ); init ( _imgInit, w, h, .0 ); init ( _imgA, w, h, .0 ); init ( _imgB, w, h, .0 ); //_imgHeater[w / 2][h / 2] = 1.0; // TODO: Faire une initialisation du heater propre! for ( int i = ( w / 2 ) - GRID_HEATER; i < ( w / 2 ) + GRID_HEATER; i += SPACE_HEATER ) { for ( int j = ( w / 2 ) - GRID_HEATER; j < ( w / 2 ) + GRID_HEATER; j += SPACE_HEATER ) { _imgHeater[i][j] = 1.0; } } erase ( _imgHeater, _imgInit ); diffuse ( _imgInit, _imgA ); erase ( _imgHeater, _imgA ); fillImage ( _imgA ); }
TEST_C(NodeRemovalTest, onlyPixelsAssignedToNodeAreUpdated) { DummyMinMaxTreeImageType image(2, 2); auto levelHeights = makeLevelHeights({ 3018, 91314 }); auto lowerPixelColor = levelHeights[0]; auto higherPixelColor = levelHeights[1]; fillImage(image, higherPixelColor); image.setPixel(0, 0, lowerPixelColor); image.assignPixelToLatestNode(0, 0); image.assignPixelToLatestNode(1, 0); image.assignPixelToNewNode(0, 1); image.assignPixelToLatestNode(1, 1); auto& higherNode = image.getPixelNode(1, 1); image.removeNode(higherNode); assertThat(image.getPixelValue(0, 0)).isEqualTo(lowerPixelColor); assertThat(image.getPixelValue(1, 0)).isEqualTo(higherPixelColor); assertThat(image.getPixelValue(0, 1)).isEqualTo(lowerPixelColor); assertThat(image.getPixelValue(1, 1)).isEqualTo(lowerPixelColor); }
//////////////////////////////////////////////////////////////////////////////// // new prosilica interface. void GazeboRosProsilica::pollCallback(polled_camera::GetPolledImage::Request& req, polled_camera::GetPolledImage::Response& rsp, sensor_msgs::Image& image, sensor_msgs::CameraInfo& info) { if (!this->rosnode_->getParam(this->mode_param_name,this->mode_)) this->mode_ = "streaming"; /// @todo Support binning (maybe just cv::resize) /// @todo Don't adjust K, P for ROI, set CameraInfo.roi fields instead /// @todo D parameter order is k1, k2, t1, t2, k3 if (this->mode_ != "polled") { rsp.success = false; rsp.status_message = "Camera is not in triggered mode"; return; } if (req.binning_x > 1 || req.binning_y > 1) { rsp.success = false; rsp.status_message = "Gazebo Prosilica plugin does not support binning"; return; } // get region from request if (req.roi.x_offset <= 0 || req.roi.y_offset <= 0 || req.roi.width <= 0 || req.roi.height <= 0) { req.roi.x_offset = 0; req.roi.y_offset = 0; req.roi.width = this->width_; req.roi.height = this->height; } const unsigned char *src = NULL; ROS_ERROR("roidebug %d %d %d %d", req.roi.x_offset, req.roi.y_offset, req.roi.width, req.roi.height); // signal sensor to start update (*this->image_connect_count_)++; // wait until an image has been returned while(!src) { { // Get a pointer to image data src = this->parentSensor->GetCamera()->GetImageData(0); if (src) { // fill CameraInfo this->roiCameraInfoMsg = &info; this->roiCameraInfoMsg->header.frame_id = this->frame_name_; common::Time roiLastRenderTime = this->parentSensor_->GetLastUpdateTime(); this->roiCameraInfoMsg->header.stamp.sec = roiLastRenderTime.sec; this->roiCameraInfoMsg->header.stamp.nsec = roiLastRenderTime.nsec; this->roiCameraInfoMsg->width = req.roi.width; //this->parentSensor->GetImageWidth() ; this->roiCameraInfoMsg->height = req.roi.height; //this->parentSensor->GetImageHeight(); // distortion #if ROS_VERSION_MINIMUM(1, 3, 0) this->roiCameraInfoMsg->distortion_model = "plumb_bob"; this->roiCameraInfoMsg->D.resize(5); #endif this->roiCameraInfoMsg->D[0] = this->distortion_k1_; this->roiCameraInfoMsg->D[1] = this->distortion_k2_; this->roiCameraInfoMsg->D[2] = this->distortion_k3_; this->roiCameraInfoMsg->D[3] = this->distortion_t1_; this->roiCameraInfoMsg->D[4] = this->distortion_t2_; // original camera matrix this->roiCameraInfoMsg->K[0] = this->focal_length_; this->roiCameraInfoMsg->K[1] = 0.0; this->roiCameraInfoMsg->K[2] = this->cx_ - req.roi.x_offset; this->roiCameraInfoMsg->K[3] = 0.0; this->roiCameraInfoMsg->K[4] = this->focal_length_; this->roiCameraInfoMsg->K[5] = this->cy_ - req.roi.y_offset; this->roiCameraInfoMsg->K[6] = 0.0; this->roiCameraInfoMsg->K[7] = 0.0; this->roiCameraInfoMsg->K[8] = 1.0; // rectification this->roiCameraInfoMsg->R[0] = 1.0; this->roiCameraInfoMsg->R[1] = 0.0; this->roiCameraInfoMsg->R[2] = 0.0; this->roiCameraInfoMsg->R[3] = 0.0; this->roiCameraInfoMsg->R[4] = 1.0; this->roiCameraInfoMsg->R[5] = 0.0; this->roiCameraInfoMsg->R[6] = 0.0; this->roiCameraInfoMsg->R[7] = 0.0; this->roiCameraInfoMsg->R[8] = 1.0; // camera projection matrix (same as camera matrix due to lack of distortion/rectification) (is this generated?) this->roiCameraInfoMsg->P[0] = this->focal_length_; this->roiCameraInfoMsg->P[1] = 0.0; this->roiCameraInfoMsg->P[2] = this->cx_ - req.roi.x_offset; this->roiCameraInfoMsg->P[3] = -this->focal_length_ * this->hack_baseline_; this->roiCameraInfoMsg->P[4] = 0.0; this->roiCameraInfoMsg->P[5] = this->focal_length_; this->roiCameraInfoMsg->P[6] = this->cy_ - req.roi.y_offset; this->roiCameraInfoMsg->P[7] = 0.0; this->roiCameraInfoMsg->P[8] = 0.0; this->roiCameraInfoMsg->P[9] = 0.0; this->roiCameraInfoMsg->P[10] = 1.0; this->roiCameraInfoMsg->P[11] = 0.0; this->camera_info_pub_.publish(*this->roiCameraInfoMsg); // copy data into image_msg_, then convert to roiImageMsg(image) this->image_msg_.header.frame_id = this->frame_name_; common::Time lastRenderTime = this->parentSensor_->GetLastUpdateTime(); this->image_msg_.header.stamp.sec = lastRenderTime.sec; this->image_msg_.header.stamp.nsec = lastRenderTime.nsec; //unsigned char dst[this->width_*this->height]; /// @todo: don't bother if there are no subscribers // copy from src to image_msg_ fillImage(this->image_msg_, this->type_, this->height_, this->width_, this->skip_*this->width_, (void*)src ); /// @todo: publish to ros, thumbnails and rect image in the Update call? this->image_pub_.publish(this->image_msg_); { // copy data into ROI image this->roiImageMsg = ℑ this->roiImageMsg->header.frame_id = this->frame_name_; common::Time roiLastRenderTime = this->parentSensor_->GetLastUpdateTime(); this->roiImageMsg->header.stamp.sec = roiLastRenderTime.sec; this->roiImageMsg->header.stamp.nsec = roiLastRenderTime.nsec; // convert image_msg_ to a CvImage using cv_bridge boost::shared_ptr<cv_bridge::CvImage> img_bridge_; img_bridge_ = cv_bridge::toCvCopy(this->image_msg_); // for debug //cvNamedWindow("showme",CV_WINDOW_AUTOSIZE); //cvSetMouseCallback("showme", &GazeboRosProsilica::mouse_cb, this); //cvStartWindowThread(); //cvShowImage("showme",img_bridge_.toIpl()); // crop image to roi cv::Mat roi(img_bridge_->image, cv::Rect(req.roi.x_offset, req.roi.y_offset, req.roi.width, req.roi.height)); img_bridge_->image = roi; // copy roi'd image into roiImageMsg img_bridge_->toImageMsg(*this->roiImageMsg); } } } usleep(100000); } (*this->image_connect_count_)--; rsp.success = true; return; }
void RipplingMOO::animationStep(bool& isNeedUpdateView) { t += dt; fillImage(t); }