mat

Convert mat file to pandas dataframe

牧云@^-^@ 提交于 2019-12-13 15:08:58
问题 I want to convert this file to pandas dataframe. import pandas as pd import scipy.io mat = scipy.io.loadmat('cardio.mat') cardio_df = pd.DataFrame(mat) I get this error : Exception: Data must be 1-dimensional 回答1: It seems mat is a dict containing X of shape (1831, 21) , y with shape (1831, 1) , and some metadata. Assuming X is the data and y are the labels for the same, you can stack them horizontally with np.hstack and load them into pandas: In [1755]: mat = scipy.io.loadmat('cardio.mat')

Fail assertion opencv mat.inl.hpp line 930

非 Y 不嫁゛ 提交于 2019-12-13 08:29:55
问题 I have a trivial problem but I don't know how to solve it. I just wanna do a simple "foreach" of a Mat to view rgb values. I have next code: for(int i=0; i<mat.rows; i++) { for(int j=0; j<mat.cols; j++) { int value_rgb = mat.at<uchar>(i,j); cout << "(" << i << "," << j << ") : " << value_rgb <<endl; } } The mat is 200 rows x 200 cols. When I print on console the results, just in the final the programs fails with next error: **OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 <

Converting from RGB to Lαβ Color spaces and converting it back to RGB using OpenCV

邮差的信 提交于 2019-12-13 07:16:30
问题 I am currently trying to convert colors between RGB (red, green, blue) color space and Lαβ color space, Based on the details in the this paper. My difficulties are in reversing the conversion process. When the result is not as same as initial RGB Mat. I think I missing something in type castings between Mats but I can't tell what is it! here is my code: <!-- language: lang-cc --> Mat DetectTrackFace::RGB2LAlphBeta(Mat &src) { Mat dest; Mat L_AlphBeta(src.rows, src.cols, CV_32FC3); //cvtColor

Convert BufferedImage TYPE_INT_RGB to OpenCV Mat Object

一曲冷凌霜 提交于 2019-12-13 06:04:09
问题 I am storing BufferedImages inside a MySQL database and retrieve them to a java application. The BufferedImages are of type TYPE_INT_RGB. How can i convert that image to a OpenCV Mat object? I do always get a java.lang.UnsupportedOperationException: Mat data type is not compatible: Exception. Can somebody help? 回答1: Got it on my own. int[] data = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4); IntBuffer intBuffer =

Access to image values using a Mat of coordinates (OpenCV/C++)

别说谁变了你拦得住时间么 提交于 2019-12-13 01:09:36
问题 In openCV(C++) I have an image IMG and I'd like to extract the values of each pixel at positions store in coor . Is it possible to get this pixel values in an efficient way? Is a foor loop (using .at(i,j) ) efficient ?Is there a built-in function for doing this? This is my code: cv::Mat IMG = cv::imread("image.png",CV_LOAD_IMAGE_GRAYSCALE); cv::Mat coor = (cv::Mat_<float>(3,2) << 1, 0, 0, 1, 2, 2); // search coordinates cv::Mat pixel_values; // and I'd like to do something like this: //This

OpenCv round after division

喜夏-厌秋 提交于 2019-12-13 00:34:23
问题 Looking at the following code Blue = channel[0]; Green = channel[1]; Red = channel[2]; Mat G = (Green + Blue) / 2; where Red Green and Blue are the channels of an image. Where the sum of Green and Blue is odd, sometimes it make a round and sometimes a "fix". For example for a Green pixel with value 120 and Blue 45, the G value is 82 (so that it takes just the integer part of 82,5). While in another case where the Green is 106 and the Blue is 33 i get the value 70 for that element of G (so

Convert cv::Mat to std::vector without copying

送分小仙女□ 提交于 2019-12-12 06:17:01
问题 I've this function: void foo(cv::Mat &mat){ float *p = mat.ptr<float>(0); //modify mat values through p } And I have this code that calls the function: void bar(std::vector<unsigned char> &vec){ //... cv::Mat res(m, n, CV_32FC1, (void *)&workspace.front()); } However, the code above has a performance problem: vec isn't probably aligned. In fact, the Intel compiler says that reference *out has unaligned access . I hope that this is the reason. Btw, as I found out in this question, cv::Mat is

How to pass managed Bitmap from C# to wrapped unmanaged OpenCV's Mat

孤街浪徒 提交于 2019-12-12 06:13:25
问题 I have a project with 3 parts: Managed C# project with a callback which gives me a Bitmap (it should have PixelFormat = Format24bppRgb). I've tried several ways to convert the Bitmap into something I could pass to part 2, that's the last thing I've tried: public int BufferCB(IntPtr pBuffer, int BufferLen) { byte[] aux = new byte[BufferLen]; Marshal.Copy(pBuffer, aux, 0, BufferLen); String s_aux = System.Text.Encoding.Default.GetString(aux); wrappedClassInstance.GetBitmap(s_aux); } Managed C++

generate cv::Mat out of a text file

为君一笑 提交于 2019-12-12 04:59:01
问题 I used this piece of code to write descriptors in a text file , but I dont know how to laod them back in a cv::Mat again, what is the function that does the opposite !! How to crete a SIFT's descriptors database 回答1: You can use the XML/YAML file storages provided by the OpenCV class Filestorage. The question is already answered here. 来源: https://stackoverflow.com/questions/23151295/generate-cvmat-out-of-a-text-file

Assigning a variable with zero value if not existing in loaded file (Octave)

给你一囗甜甜゛ 提交于 2019-12-12 04:36:27
问题 The Case1.Mat file contains X Y Z 2 6 3 3 7 4 4 8 6 5 9 8 load(Case1.Mat); # loaded a Case1.Mat file in Octave label=[{X;Y;Z;V}]; # I have a matrix of predefined variables Nrow=numel(label); ResMat=ones(Nrow,1); for k=1:Nrow; ResMat(k,1)=max(label{k,1}); End I have just shown the example of simplification of my problem, however in my case the Mat file contains >300 Variables, and for each case the number of variables changes. Hence I have defined a label matrix with all the variables. In the