Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all 41027 articles
Browse latest View live

Wierd bug - cvTranspose corrupts images.

$
0
0
Hi, I have been tracking this bug for quite some time now, so any suggestion would be welcome. I use OpenCV as part of the server, which uses OpenCV for image processing. The server is written in Golang and uses our custom binding to OpenCV. One operation is to rotate images, and it works 99% of time correctly when using the same set of images. Very very rarely the input image will fail (see attachments). There is nothing special about input images. Actually, the same image would go through rotation without corruption at any other time before suddenly failing. On the server with 8 instances changing content every minute, it would fail once every few days. I have written the unit test that repeats rotate and some other operations in multiple threads running in a loop. Test does not seam to catch any corruptions, but it does create heavy CPU and memory load. [Snippet showing how do we use cvTranspose() to implement image rotation. (It is a Go code using C bindings)]( https://pastebin.com/i00xGCej) I have already posted the same question to slack, and I was given the recommendation to update to v 3.x.x. and use new 'rotate()' function. I will probably try this, but the reason I post this here again is: - My concern is that there is either bug in OpenCV cvTranspose function (unlikely) or that there is the problem with the way we use OpenCV (more likely), and that in that case changing the function won't solve any problem. It is really hard for me right now to confirm that after the change I did solve the problem, because of bugs rare occurrence. - as a reference for a possible future bug report Samples of corrupted images dumpede by 'cvTranspose()'. Images are gray but are actualy in RGBA format. [sample1](/upfiles/15131738284685009.png) [sample2](/upfiles/15131738932708457.png) > root@1c4b88d5e5b5:~/vss# uname -a>Linux 1c4b88d5e5b5 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux>root@1c4b88d5e5b5:~/vss# cat /etc/issue Ubuntu 16.04 LTS \n \l>root@1c4b88d5e5b5:~/vss# dpkg -l | grep opencv>ii libopencv-core2.4v5:amd64 2.4.9.1+dfsg-1.5ubuntu1 amd64 computer vision core library>ii libopencv-imgproc2.4v5:amd64 2.4.9.1+dfsg-1.5ubuntu1 amd64 computer vision Image Processing library>golang version 1.9.2> $ docker version # servers is running inside docker >Client:> Version: 17.09.0-ce> API version: 1.32>Go version: go1.8.3> Git commit: afdb6d4> Built: Tue Sep 26 22:42:18 2017> OS/Arch: linux/amd64>Server:> Version: 17.09.0-ce> API version: 1.32 (minimum version 1.12)> Go version: go1.8.3> Git commit: afdb6d4> Built: Tue Sep 26 22:40:56 2017> OS/Arch: linux/amd64> Experimental: false

Flip Video in openCV

$
0
0
I am having a problem when using the OpenCV facial recognition. My webcam is mounted upside down, so I have flipped the video with `pushMatrix`, however the video is still coming in upside down in OpenCV I believe, therefore it is not recognizing anything. How can I flip "video"? void draw() { scale(2); pushMatrix(); scale(1,-1); translate(0, -video.height); image(video, 0, 0); popMatrix(); opencv.loadImage(video); noFill(); stroke(0, 255, 0); strokeWeight(3); Rectangle[] faces = opencv.detect(); println(faces.length); for (int i = 0; i < faces.length; i++) { println(faces[i].x + "," + faces[i].y); rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);

vector point in SVG image file

$
0
0
Hi, may I know is it any way to show all the vector point of SVG image file in a Mat format? I have try to search the code for it but unfortunately i cant find any related code..Really appreciate if i can get the answer from you all

Int object not iterable? (Python) (URGENT, NEEDED BY TONIGHT)

$
0
0
#This is really urgent and I need this tomorrow, I cant seem to find a solution anywhere, I have a script that runs a facial recognition script, but for some reason its telling me this exact error: File "box.py",line 98, in label,confidence = model.predict(crop) TypeError: 'int' object is not iterable #My code thats actually important to the problem: import cv2 -Creates model to be the facerecognizer model = cv2.face.createEigenFaceRecognizer() -Defines the model as a training image taken previously model.load(config.TRAINING_FILE) -Initializes the camera as camera camera = config.get_camera() -Takes a picture using the camera image = camera.read() -Converts to grayscale image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) -Results if it found a face result = face.detect_single(image) -Tells you to keep taking a picture until you have a face recognized if result is None: print 'Could not see face! Retake picture!' continue -gets dimensions of the face x,y,w,h = result -resizes the face crop = face.resize(face.crop(image, x, y, w, h)) #Tests face against the previously taken model label, confidence = model.predict(crop) **<--- This is where the error is** -Im not 100% as to what this does, I got this part on the internet result = cv2.face.MinDistancePredictCollector() model.predict(crop) label = result.getLabel() confidence = result.getDist() Sorry about the weird formatting, the thing was being dumb and I couldnt fix it, anyways Thats basically it (Theres obviously some more code set up inside and between but it isnt important or relevant to the issue, at least I dont think, I need this urgently so please somebody respond quick, Im using Python 2.7 with opencv 3.1.0 on a raspbian raspberry pi 3 if you need that information

2%] Built target opencv_cvv_automoc Makefile:160: recipe for target 'all' failed

$
0
0
Tried to build with "cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D WITH_CUBLAS=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON .." when i run cmake its failing at "Generating moc_singlefilterview.cpp Generating moc_translationsmatchview.cpp [ 2%] Built target opencv_cvv_automoc Makefile:160: recipe for target 'all' failed make: *** [all] Error 2 " I was trying to install Opencv3.1.0 with CUDA 8 in Ubuntu 14.04 Please guide me.

Can I find out how the training data matches the current data?

$
0
0
I am doing character recognition through knn using opencv 3.2.0 When recognizing, two result come out. If k is 1, how much does the training data match the current data as a percentage?

Access violation when using imwrite to save an imageMat

$
0
0
Hi everybody! I'm having an extremely annoying issue when tryig to save a PGN file with the depth value of a Kinect frame. I already have the millimeters Matrix in format. cv::Mat imageMat = cv::Mat(height, width, CV_16UC1); I'm having a problem when I execute this: vector pars; vector image; pars.push_back(CV_IMWRITE_PNG_COMPRESSION); pars.push_back(3); char *fmt = (char *)".png"; cv::imencode(fmt, imageMat, image, pars); cv::imwrite("data.png", imageMat, pars); The problem is actually in the last two lines. They both returns the same "Access violation while reading location at..." Could anybody help me? I'm using OpenCV 3.0 on Visual Studio 2013. Thank you all!

Find contour confusion

$
0
0
This is my original image ![image description](/upfiles/15132442621798222.png) I have detected total `6 approximate squares` in this image shown below using `cv2.findContours` if we count as seen on the detected image below with bounding box around them. ![image description](/upfiles/1513244429261434.png) I checked this [Contours Hierarchy](https://docs.opencv.org/trunk/d9/d8b/tutorial_py_contours_hierarchy.html) Tried out all the Hierarchy mentioned in the above link to get only `6` contours but least contour being detected is `10` I just need to detect `squares` not the entire family 'GrandFather' `GrandMother` `Father` `Mother` `etc` Can anyone help me out here?

crop image using points

$
0
0
I have converted one image into gray scale and hsv now want to get part of hsv from original image. Can someone help me in this?> cv::Mat source=[self cvMatFromUIImage:> self.imgTaken];>> cv::Mat hsv;>> cv::cvtColor(source, hsv,> cv::COLOR_BGR2HSV); cv::Mat Img;>> cv::cvtColor(hsv, Img,> cv::COLOR_BGR2GRAY);

Convert cv::UMat to cv::ogl::Texture2D?

$
0
0
I want to use opencl and opengl together. I have a cv::UMat and i want to convert it to cv::ogl::Texture2D in order to bind and render with opengl. I have already a code that is worked fine but it takes too much of time: cv::UMat _umat; // initialized before (a 1920*1080 image) cv::ogl::Texture2D tex(_umat); // it takes about 14 millisecond on my machine (cpu: corei7, gpu: GTX-1080) tex.bind(); // opengl code ... // ... Is there another way to do it more efficient?? It seems that the reason it consumes too much of time is that the data is copied but we should convert it. There is another function in opencv : `void convertToGLTexture2D(InputArray src, Texture2D& texture)`. I have tried it but its not workd or maybe I do not know how to use it. I used it like this: cv::ogl::ocl::initializeContextFromGL(); cv::ogl::Texture2D tex; tex.create(1080,1920, cv::ogl::Texture2D::RGB); cv::ogl::convertToGLTexture2D(_umat, tex); When I run it, I encounter a segmentation fault: OpenCV Error: Unknown error code -220 (OpenCL: clEnqueueAcquireGLObjects failed) in convertToGLTexture2D Could you help me?

Detecting shapes using open Cv in Android

$
0
0
I have requirement to detect the measurements of parcels before accepting it from the user. When I searched found out that Open CV is the better solution for the requirement but till now I didn't get any solution. Please share the java code for my android project

Android library with OpenCv in Unity :Failure to initialize your hardware doesn't support this application sorry

$
0
0
Hi, I try to create android native library in Android studio with Opencv and I use library and build in Unity but gives error: Failure to initialize your hardware doesn't support this application I tried only opencv library in android studio and build apk in Android studio .it worked ... I dont know what problem is because Im new about both Opencv and android studio

cv::VideoCapture::get(CAP_PROP_POS_FRAMES) does not work with GStreamer?

$
0
0
Until 3.1 I used OpenCV with ffmpeg. Setting and getting the video frame index using CAP_PROP_POS_FRAMES worked without any problems (video cv::VideoCapture::set and ::get). Now I built OpenCV 3.3.1 with Visual Studio 2015 and GStreamer 1.12.3 (all plugins installed). Videos are read and written without any problems. But as soon as I try to get the video frame index - with the same videos that worked with ffmpeg - it fails: (cpp-tutorial-bg_sub.exe:13676): GStreamer-CRITICAL **: gst_query_set_position: assertion 'format == g_value_get_enum (gst_structure_id_get_value (s, GST_QUARK (FORMAT)))' failed warning: Cannot query video position: status=1 value=-1 duration=18795 (C:\opencv\modules\videoio\src\cap_gstreamer.cpp:949) The first warning message is from GStreamer (GST_DEBUG=4), the second the subsequent message from OpenCV (see line 948 of [cap_gstreamer.cpp](https://github.com/opencv/opencv/blob/3.3.1/modules/videoio/src/cap_gstreamer.cpp)) Above message is from the tutorial project bg_sub. What do I do wrong? Thank you.

Trying to create a New a Api in OpenCv in Windows?

$
0
0
opencv_Videoio. Trying to Add a New Api in videocapture class.. Ending up in the linking error? Added: 1. Added a api declaration in the videoio.hpp 2. Definition for that api in the cap_dshow.cpp and declaration for that in the cap_dshow.hpp Can Anyone please answer this one ? Thanks In ADVANCE.. Error 3 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::VideoCapture::CheckDevices(int)" (?CheckDevices@VideoCapture@cv@@UAEXH@Z) F:\OpenCv Projects\opencv_3.3.1\build\modules\videoio\cap.obj opencv_videoio Error 4 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::VideoCapture::CheckDevices(int)" (?CheckDevices@VideoCapture@cv@@UAEXH@Z) F:\OpenCv Projects\opencv_3.3.1\build\modules\videoio\opencv_videoio_pch.obj opencv_videoio Error 5 error LNK1120: 1 unresolved externals F:\OpenCv Projects\opencv_3.3.1\build\bin\Release\opencv_videoio331.dll opencv_videoio

drawContours throws exception

$
0
0
Hello, I use opencv3.3.1 from ros-kinetic When executing this code > vector > testContour; > vector testedge; > testedge.push_back(Point2i(240,240)); > testedge.push_back(Point2i(120,240)); > testedge.push_back(Point2i(120,120)); > testedge.push_back(Point2i(240,120)); > testContour.push_back(testedge); > vector testedge2; > testedge2.push_back(Point2i(200,200)); > testedge2.push_back(Point2i(100,200)); > testedge2.push_back(Point2i(100,100)); > testedge2.push_back(Point2i(200,100)); > testContour.push_back(testedge2); > drawContours(image, testContour, -1,/*it->getColor()*/Scalar(255,255,255),CV_FILLED,LINE_8); i get the following error: > OpenCV Error: Assertion failed > (reader.ptr != __null) in > cvDrawContours, file > /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/drawing.cpp, line 2603 terminate called after > throwing an instance of > 'cv::Exception' what(): > /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/drawing.cpp:2603: > error: (-215) reader.ptr != __null in > function cvDrawContours now this only happens after updating the ros packages... before it ran fine..... now i don't understand why exactly the reader.ptr() is __null, since my counturs vector is filled as u can see above, also google is quite emoty of that problem. best regards, homes edit: it works now with the testContour, but it doesn't appear to work with a dynamically filled Contour vector. Am I correct in my assumption, that this means i am trying to pass a undefined pointer to the drawContours function?

How to find a part of an image with the highest density of feature matches

$
0
0
As the title says, I want to find the position with the most feature matches from an image. What I'm looking for is the part of the image where the feature matches have the highest density. I know that the question can be easily misunderstood, therefore I added a photo describing better what I mean. In the end I want to have a rectangle around the position with the most feature points within, where the max distance between 2 nearest points should be smaller than a threshold. In the image added I've manually drawn a rectangle around the area with the highest density of feature points. I could implement a not so efficient way, but I would like to know if there's any OpenCV function that could be useful or if someone knows a smart way to do it. Thank you! ![image description](/upfiles/15132584888295702.png)

[ 20%] Built target opencv_cvv_automoc Makefile:160: recipe for target 'all' failed make: *** [all] Error 2

$
0
0
It's the second time that I want to `make` the opencv but it gives me such errors: /home/m/Downloads/opencv/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory [ 20%] Built target opencv_cvv_automoc Makefile:160: recipe for target 'all' failed make: *** [all] Error 2 I checked and saw the file doesn't exist! I downloded the opencv zip file from sourceforge and github, but both of them had some missing files! why this happens? I used this command to build it: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON .. And `make -j8` to make it.

Can I show some image in my program beside the executation at the same time?

$
0
0
I had a problem with GTK+. I had a program that I used for my robot, I wanted to show an image respect to my robot state beside execution of my robot code, but GTK had a main loop that when I opened a window to showing image, it locked and didn't execute the rest of code! So I am interested to know how opencv works? can I show an image in my program and other parts of program work beside it(I mean the image is shown inside the display and robot works and if it changed it's state the image will update )

Problem with kmeans in opencv

$
0
0
#include #include #include #include #include #include #include #include #include #include "common_code.hpp" #define IMG_WIDTH 300 int main(int argc, char * argv[]) { TCLAP::CmdLine cmd("Trains and tests a BoVW model", ' ', "0.0"); TCLAP::ValueArg basenameArg("b", "basename", "basename for the dataset.", false, "./data", "pathname"); cmd.add(basenameArg); TCLAP::ValueArg configFile("c", "config_file", "configuration file for the dataset.", false, "02_ObjectCategories_conf.txt", "pathname"); cmd.add(configFile); TCLAP::ValueArg n_runsArg("r", "n_runs", "Number of trials train/test to compute the recognition rate. Default 10.", false, 10, "int"); cmd.add(n_runsArg); TCLAP::ValueArg ndesc("", "ndesc", "[SIFT] Number of descriptors per image. Value 0 means extract all. Default 0.", false, 0, "int"); cmd.add(ndesc); TCLAP::ValueArg keywords("w", "keywords", "[KMEANS] Number of keywords generated. Default 100.", false, 100, "int"); cmd.add(keywords); TCLAP::ValueArg ntrain("", "ntrain", "Number of samples per class used to train. Default 15.", false, 15, "int"); cmd.add(ntrain); TCLAP::ValueArg ntest("", "ntest", "Number of samples per class used to test. Default 50.", false, 50, "int"); cmd.add(ntest); TCLAP::ValueArg k_nn("", "k_nn", "[KNN] Number k neighbours used to classify. Default 1.", false, 1, "int"); cmd.add(k_nn); cmd.parse(argc, argv); // --------------- MAIN BLOCK --------------- std::vector categories; std::vector samples_per_cat; std::string dataset_desc_file = basenameArg.getValue() + "/" + configFile.getValue(); int retCode; if ((retCode = load_dataset_information(dataset_desc_file, categories, samples_per_cat)) != 0) { std::cerr << "Error: could not load dataset information from '" << dataset_desc_file << "' (" << retCode << ")." << std::endl; exit(-1); } std::cout << "Found " << categories.size() << " categories: "; if (categories.size()<2) { std::cerr << "Error: at least two categories are needed." << std::endl; return -1; } for (size_t i=0;i rRates(n_runsArg.getValue(), 0.0); // Repeat training+test for (int trial=0; trial> train_samples; std::vector> test_samples; create_train_test_datasets(samples_per_cat, ntrain.getValue(), ntest.getValue(), train_samples, test_samples); //----------------------------------------------------- // TRAINING //----------------------------------------------------- std::clog << "Training ..." << std::endl; std::clog << "\tCreating dictionary ... " << std::endl; std::clog << "\t\tComputing descriptors..." << std::endl; cv::Mat train_descs; cv::Mat1f totalmat; std::vector ndescs_per_sample; ndescs_per_sample.resize(0); cv::Mat labels; cv::Mat1f centers; std::vector bovw; for (size_t c = 0; c < train_samples.size(); ++c) { std::clog << " " << std::setfill(' ') << std::setw(3) << (c * 100) / train_samples.size() << " % \015"; for (size_t s = 0; s < train_samples[c].size(); ++s) { std::string filename = compute_sample_filename(basenameArg.getValue(), categories[c], train_samples[c][s]); cv::Mat img = cv::imread(filename, cv::IMREAD_GRAYSCALE); if (img.empty()) { std::cerr << "Error: could not read image '" << filename << "'." << std::endl; exit(-1); } else { // Fix size: width =300px //! \todo TO BE COMPLETED cv::Size size(300,300*img.rows/300*img.cols); resize(img,img,size); // Extract SIFT descriptors //----------------------------------------------------- cv::Mat1f descs; descs = extractSIFTDescriptors(img, ndesc.getValue()); //devuelve una matriz de 100 filas y 128 columnas if (c==0 and s==0) //Para evitar que en la primera no descs.copyTo(totalmat); else cv::vconcat(totalmat,descs,totalmat);//Concatenamos todas las matrices con los puntos caracteristicos. bovw.push_back(descs); //Gurdamos cada imagen por separado en un vector de imagenes std::cout << totalmat.size() < KNN=cv::ml::KNearest::create(); //centers almacena los valores de los centroides en cada fila std::vector etiquetas;//creo un vector donde ire guardando cada una de las etiquetas de centers KNN->train(centers,cv::ml::ROW_SAMPLE,etiquetas); KNN->save("diccionario.yml"); // Compute BoVW for each image //----------------------------------------------------- std::clog << "\tComputing BoVW ... " << std::endl; //For each train image, compute the corresponding bovw. std::clog << "\t\tGenerating a bovw descriptor per training image." << std::endl; //! \todo TO BE COMPLETED // Define the classifier type and train it //----------------------------------------------------- //! \todo TO BE COMPLETED //----------------------------------------------------- // TESTING //----------------------------------------------------- std::clog << "Testing .... " << std::endl; //load test images, generate SIFT descriptors and quantize getting a bovw for each image. //classify and compute errors. std::vector true_labels; //For each test image, compute the corresponding bovw. std::clog << "\tCompute image descriptors for test images..." << std::endl; cv::Mat test_bovw; //! \todo TO BE COMPLETED std::clog << "\tThere are " << test_bovw.rows << " test images." << std::endl; //Classify the test samples. std::clog << "\tClassifing test images." << std::endl; cv::Mat predicted_labels; //compute the classifier's confusion matrix. std::clog << "\tComputing confusion matrix." << std::endl; cv::Mat confusion_mat = compute_confusion_matrix(categories.size(), cv::Mat(true_labels), predicted_labels); CV_Assert(int(cv::sum(confusion_mat)[0]) == test_bovw.rows); double rRate_mean, rRate_dev; compute_recognition_rate(confusion_mat, rRate_mean, rRate_dev); std::cerr << "Recognition rate mean = " << rRate_mean * 100 << "% dev " << rRate_dev * 100 << std::endl; rRates[trial]=rRate_mean; } //Saving the best models: dictionary and classifier, format YML //! \todo TO BE COMPLETED std::clog << "###################### FINAL STATISTICS ################################" << std::endl; double rRate_mean = 0.0; double rRate_dev = 0.0; //! \todo TO BE COMPLETED std::clog << "Recognition Rate mean " << rRate_mean*100.0 << "% dev " << rRate_dev*100.0 << std::endl; return 0; } **i32romer@AAVLD026:~/Desktop/FSIV/Practica4$ ./train_bovw Found 2 categories: airplanes Motorbikes ######### TRIAL 1 ########## Training ... Creating dictionary ... Computing descriptors... [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] [128 x 0] Generating 100 keywords ... OpenCV Error: Assertion failed (N >= K) in kmeans, file /INSTALACIONES/2017-2018/opencv-3.3.0/modules/core/src/kmeans.cpp, line 244 terminate called after throwing an instance of 'cv::Exception' what(): /INSTALACIONES/2017-2018/opencv-3.3.0/modules/core/src/kmeans.cpp:244: error: (-215) N >= K in function kmeans Abortado** That is my mistake. I've been looking for the fault for several hours and I can not find anything. I think my cv :: vconcat does not work well. Can someone help me ?. a greeting

Convert Cubemap coordinates to equivalents in Equirectangular

$
0
0
I have a set of coordinates of a 6-image Cubemap (Front, Back, Left, Right, Top, Bottom) as follows: [ [160, 314], Front; [253, 231], Front; [345, 273], Left; [347, 92], Bottom; ... ] Each image is 500x500p, being [0, 0] the top-left corner. I want to convert these coordinates to their equivalents in equirectangular, for a 2500x1250p image. I don't need to convert the whole image, just the set of coordinates. Is there any straight-forward conversion for a specific pixel?
Viewing all 41027 articles
Browse latest View live