mat

PyQt/PySide: How do I convert QImage into OpenCV's MAT format

北城余情 提交于 2019-11-29 23:32:57
问题 I'm looking to create a function for converting a QImage into OpenCV's (CV2) Mat format from within the PyQt. How do I do this? My input images I've been working with so far are PNGs (either RGB or RGBA) that were loaded in as a QImage. Ultimately, I want to take two QImages and use the matchTemplate function to find one image in the other, so if there is a better way to do that than I'm finding now, I'm open to that as well. But being able to convert back and forth between the two easily

How to get Mat with a drawable input in Android using OpenCV

三世轮回 提交于 2019-11-29 18:44:43
问题 I have some image files in the drawable folder. And now, I want to convert them into opencv Mat object. I've found a function: Mat img = Highgui.imread(inFile); which is reading a file path to get the Mat. However, I can't get path of my images as I can only read them by using their id like R.drawable.img1. How could I achieve what I want? 回答1: This should do Mat img = Utils.loadResource(context, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR); Imgproc.cvtColor(img, gryimg, Imgproc.COLOR_RGB2BGRA

convert keypoints to mat or save them to text file opencv

邮差的信 提交于 2019-11-29 15:05:58
问题 I have extracted SIFT features in (opencv open source) and they are extracted as keypoints. Now, I would like to convert them to Matrix (With their x,y coordinates) or save them in a text file... Here, you can see a sample code for extracting the keypoints and now I would like to know how convert them to MAT or save them in txt, xml or yaml... cv::SiftFeatureDetector detector; std::vector<cv::KeyPoint> keypoints; detector.detect(input, keypoints); 回答1: Convert to cv::Mat is as follows. std:

OpenCV cv::Mat set if

二次信任 提交于 2019-11-29 09:39:36
Is there a simple way to set all values in a cv::Mat to a given value if they fulfill some condition. For instance, I have CV_32FC1, and I want set all values which are 0 to 20. In MATLAB I would have simply done this: M(M == 0) = 20; You can use cv::Mat mask = M == 0; M.setTo(0.5, mask); However, it includes using additional memory for creating mask, but is a solution using opencv API therefore can be applied to all matrix types. If you consider performance issues, you can always refer directly to Mat::data to optimize this solution for concrete matrix type. This is a classic case for look-up

Bitmap to Mat gives wrong colors back

为君一笑 提交于 2019-11-29 07:29:33
So I make a bitmap from a blob with the next code: byte[] blob = contact.getMP(); ByteArrayInputStream inputStream = new ByteArrayInputStream(blob); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); Bitmap scalen = Bitmap.createScaledBitmap(bitmap, 320, 240, false); and it gives back the next output, which is good Then I do the following to make the bitmap into a Mat, but then my colors just change... //Mat ImageMat = new Mat(); Mat ImageMat = new Mat(320, 240, CvType.CV_32F); Utils.bitmapToMat(scalen, ImageMat); I have no idea why, nor another way to make the bitmap into a Mat. What is

Convert a string of bytes to cv::mat

余生长醉 提交于 2019-11-29 04:30:45
I need to implement a function that receives a string containing the bytes of an image (received via boost socket connection) and converts the info into an OpenCV cv::Mat . I also know the width and height of the image and its size in bytes. My function looks like this: void createImageFromBytes(const std::string& name, std::pair<int,int> dimensions, const std::string& data) { int width,height; width = dimensions.first; height = dimensions.second; //convert data to cv::Mat image std::string filepng = DATA_PATH"/" + name +".png"; imwrite(filepng, image); } Which is the best method for doing

Can I determine the number of channels in cv::Mat Opencv

南楼画角 提交于 2019-11-29 03:25:15
This maybe rudimentary, but is it possible to know how many channels a cv::Mat has? For eg, we load an RGB image, I know there are 3 channels. I do the following operations, just to get the laplacian of the image, which is straight from the Opencv Documentation. int main(int argc, char **argv) { Mat src = imread(argv[1],1),src_gray,dst_gray,abs_dst_gray; cvtColor(src,src_gray,COLOR_BGR2GRAY); GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT ); Laplacian(src_gray,dst_gray,ddepth,kernel_size,scale,delta,BORDER_DEFAULT); convertScaleAbs(dst_gray,abs_dst_gray); } After converting to

UnsatisfiedLinkError: n_Mat while using opencv2.4.3 with android 4.0

南楼画角 提交于 2019-11-28 23:55:22
i am using opencv in android. but when i am adding Mat() in my code my application unexpectedly stops after launch. my error log is as below: FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError: n_Mat at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.<init>(Mat.java:441) at com.example.imagepro.MainActivity.onCreate(MainActivity.java:36) at android.app.Activity.performCreate(Activity.java:4465) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) at android.app

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

我的未来我决定 提交于 2019-11-28 18:11:39
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 to get the good pixel in output (with cout) however in the output image (with imwrite) the pixel

Change type of Mat object from CV_32F to CV_8U

依然范特西╮ 提交于 2019-11-28 17:01:53
I tried to display an image of CV_32F type using imshow function but it showed a WHITE image . In the Documentation its given that floating point images will be mapped to 0-255 and displayed but it just showed a white image.I tried to convert it to CV_8U using Mat A=Mat::ones(300,300,CV_32FC1)*1000; do some processing - assigning float values to pixels in A ...... Mat B; A.convertTo(B,CV_8U) When I imshow 'B' i get a black & white image, there are no shades of gray . Are the float valued pixels in A properly mapped to 0-255 ? Am I doing anything wrong? Few values in A are 1000 as initialized