mat

How to edit/read pixel values in OpenCv from Mat variable?

 ̄綄美尐妖づ 提交于 2019-11-27 12:27:11
问题 I am looking for an efficient way for editing/reading pixels from Mat (or Mat3b) variable. I have used :- Image.at<Vec3b>(i,j) but it seems to be very slow. I also used this:- A.data[A.channels()*A.cols*i + j + 0] but the problem I am facing with this is when I run this loop for(i=0; j<A.rows; i++){ for(j=0; j<A.cols; j++){ A.data[A.channels()*A.cols*i + j + 0] = 0; A.data[A.channels()*A.cols*i + j + 1] = 0; A.data[A.channels()*A.cols*i + j + 2] = 0; } } only a portion of image is blackened.

c++ and opencv get and set pixel color to Mat

自作多情 提交于 2019-11-27 11:06:46
问题 I'm trying to set a new color value to some pixel into a cv::Mat image my code is below: Mat image = img; for(int y=0;y<img.rows;y++) { for(int x=0;x<img.cols;x++) { Vec3b color = image.at<Vec3b>(Point(x,y)); if(color[0] > 150 && color[1] > 150 && color[2] > 150) { color[0] = 0; color[1] = 0; color[2] = 0; cout << "Pixel >200 :" << x << "," << y << endl; } else { color.val[0] = 255; color.val[1] = 255; color.val[2] = 255; } } imwrite("../images/imgopti"+to_string(i)+".tiff",image); It seems

How to write a Float Mat to a file in OpenCV

耗尽温柔 提交于 2019-11-27 08:15:31
I have a matrix Mat B(480,640,CV_32FC1); containing floating values..I want to write this matrix to a file which could be opened in notepad or Ms word or Excel to see the values inside and for storage.... imwrite function can save 8-bit or 16-bit image only.. Drop in your suggestions if this could be done?? if yes, how ?? sansuiso Using pure OpenCV API calls: // Declare what you need cv::FileStorage file("some_name.ext", cv::FileStorage::WRITE); cv::Mat someMatrixOfAnyType; // Write to file! file << "matName" << someMatrixOfAnyType; The file extension can be xml or yml . In both cases you get

MATLAB matfile increases in size when overwriting cell data

烂漫一生 提交于 2019-11-27 07:22:23
问题 Due to large data size and frequent automatic saves I decided to change the method of saving from the standard save() function to partial saving using a matfile object: https://www.mathworks.com/help/matlab/ref/matfile.html I made this change because using save() will overwrite everything even if a minor change was made to the structure, greatly slowing the program. However I noticed that the time to save with matfile increased linearly every time it was called, and after some debugging I

C++ OpenCV image sending through socket

久未见 提交于 2019-11-27 07:01:31
I'm trying to implement a streaming service using OpenCV and sockets. The server side loads a given image and sends it to the client, which receives it through the socket and displays it. I'm having a lot of trouble, though, sending the data of the image and reconstructing it on the client side. This is the code I've made so far: Image sender: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include

Conversion from IplImage* to cv::MAT

牧云@^-^@ 提交于 2019-11-27 04:18:24
问题 I searched to convert an IplImage* to Mat, but all answers were about the conversion to cvMat. How, can I do it? and what is the difference between Mat and cvMat? Thanks in advance 回答1: here is a good solution Mat(const IplImage* img, bool copyData=false); 回答2: For the records: taking a look at core/src/matrix.cpp it seems that, indeed, the constructor cv::Mat(IplImage*) has disappeared. But I found this alternative: IplImage * ipl = ...; cv::Mat m = cv::cvarrToMat(ipl); // default additional

What is the difference between UMat and Mat in OpenCV?

自作多情 提交于 2019-11-27 03:14:15
问题 I have been through the documentation and didn't get a clear detailed description about UMat; however I think it has something to relate with GPU and CPU. Please help me out. Thank you. 回答1: Perhaps section 3 of this document will help: [link now broken] https://software.intel.com/sites/default/files/managed/2f/19/inde_opencv_3.0_arch_guide.pdf Specifically, section 3.1: A unified abstraction cv::UMat that enables the same APIs to be implemented using CPU or OpenCL code, without a requirement

How can I get and set pixel values of an EmguCV Mat image?

て烟熏妆下的殇ゞ 提交于 2019-11-26 23:35:17
问题 I'm using the EmguCV 3.0.0 wrapper to the OpenCV 3.0 library. I'm using the Mat class in a few places. Here's an example of a single channel, 8x8 image made of double values: Mat image = new Mat(8, 8, DepthType.Cv64F, 1); The Image<> class provides reasonable means for getting and setting pixel values, and the method is identical for the Matrix<> class, but it doesn't seem as obvious for the Mat class. The only way I've figured out how to set individual pixel is using a mask: // set two pixel

How to access pixel values of CV_32F/CV_64F Mat?

梦想的初衷 提交于 2019-11-26 21:36:34
问题 I was working on homography and whenever I try to check the values of H matrix (type CV_64F) using H.at<float>(i, j) I get random numbers(sometimes garbage value). I want to access pixel values of float matrix. Is there any way to do it? Mat A = Mat::eye(3, 3, CV_64F); float B; for(int i=0; i<A.rows; i++) { for(int j=0; j<A.cols; j++) { printf("%f\n", A.at<float>(i, j)); } } imshow("identity", A); waitKey(0); This shows correct image of an identity matrix but while trying to access pixel

Get frame from video with libvlc smem and convert it to opencv Mat. (c++)

↘锁芯ラ 提交于 2019-11-26 21:21:05
问题 [UPDATED WITH PARTIAL ANSWER] Here is my code: void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) { // Locking imageMutex.lock(); videoBuffer = (uint8_t *)malloc(size); *pp_pixel_buffer = videoBuffer; } void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer , int width, int height, int pixel_pitch, int size, int64_t pts) { // Unlocking imageMutex.unlock(); Mat img = Mat(Size(width,height), CV_8UC3, p_pixel_buffer); //cvtColor(img,img,CV_RGB2BGR); } int