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

Get HSV and RGB values of an image

$
0
0
im trying to get RGB values of an image. which i can get Min(R-G-B),Med(R-G-B),Max(R-G-B) also i want to get the HSV of RGB with same format HSVMIN(R-G-B), HSVMED(R-G-B), HSVMAX(R-G-B).

Geeting error while reading the xml file.

$
0
0
Hi , I am getting the error while reading the xml file. The error message is.."duplicate key". I have attached read and write function and screenshot of xml file.![image description](/upfiles/15187733094949328.png) thank you. int main() { std::vector names = { "SuperPixelno", "lValue", "aValue","bValue","xCenter","yCenter","depthValue" }; cv::FileStorage fs("FeatureVector.xml", cv::FileStorage::WRITE); superpixelSlic.writeVector(fs, names, tempCenters); fs.release(); vector readTempCenters; std::vector nm = { "SuperPixelno", "lValue", "aValue","bValue","xCenter","yCenter","depthValue" }; FileStorage fs2("FeatureVector.xml", FileStorage::READ); readVector(fs2, nm, readTempCenters); fs2.release(); return (0); } void readVector(FileStorage &fns, vector nm, vector&data) { data.clear(); CenterValues tmp; FileNode fn = fns["features"]; if (fn.empty()) { return; } for (FileNodeIterator current = fn.begin(); current != fn.end(); ++current) { //FileNode item = *current; cout << "superpixelno. " << (double)(*current)[nm[0]]; cout << "light Value " << (double)(*current)[nm[1]]; cout << "a value" << (double)(*current)[nm[2]]; cout << "b value" << (double)(*current)[nm[3]]; cout << "x Value" << (double)(*current)[nm[4]]; cout << "y Value" << (double)(*current)[nm[5]]; cout << "depth Value" << (double)(*current)[nm[6]]; } } void SuperpixelSlic:: writeVector(cv::FileStorage &fs, std::vector&names, std::vector&data) { for (int i = 0; i < data.size(); i++)![image description](/upfiles/1518773204719258.png) { fs << "features"; fs <<"{:"<< names[0] << i<

i want to use my usb camera in raspberry pi and i have written this code , its not getting any error but still my video output is not coming plz help me.

$
0
0
import cv2,io,imutils import numpy from imutils.video import VideoStream print("Starting Camera...........") webcam = VideoStream(0).start() webcam.resolution = (640, 320) detector= cv2.CascadeClassifier('haarcascade_frontalface_default.xml') cap = cv2.VideoCapture(1) def getFrame(): jpegBuffer = io.BytesIO() webcam.capture(jpegBuffer, format='jpeg') buff = numpy.fromstring(jpegBuffer.getvalue(), dtype=numpy.uint8) return cv2.imdecode(buff, 1) while(True): ret,img = cap.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = detector.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: img= cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) cv2.imshow('Screen',img) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()

Check for metamers in an image (using C++)

$
0
0
How do I check how many metamers on my image using OpenCV & C++ ? For example in this picture, what I'm trying to do is find out that box in no 1 & 5 are metamers, also box no. 3 & 6. So total I have 2 metamers (blue & yellow), and later I need to swap the color. ![image description](/upfiles/1518786834808628.png) What I've been doing so far is using inRange, and take an example of blue color range : Blue no.1 (152,42,5) - BGR order Blue no.6 (185,50,4) - BGR order Mat mask; cv::Scalar lowerb = cv::Scalar(150,20,0); cv::Scalar upperb = cv::Scalar(200,50,5); cv::inRange(frame, lowerb, upperb, mask); In this case I can define the target range, but later this colors will always programmatically change, so the target range will also change. And this also only for one color. How do I detect several colors that perceived the same when the target range isn't fixed ?

Opening an OpenCV window in a Windows Runtime component (C++) for a UWP app

$
0
0
I'm stuck with some linker errors when trying to call the imshow function in my WinRT component for a UWP app. The component simply calls imshow after a type conversion on the file name string, which is supposed to show the image in a new window. This is a proof-of-concept to show that OpenCV can be used within a UWP app without using wrappers such as EmguCV. (In the Change Log for OpenCV, it says one of the versions includes UWP build support, but it's for phones only.) On Debug x64 mode, calling imshow raises this exception: Exception thrown at 0x00007FFAAC1E3E1F (opencv_highgui310d.dll) in OpenCVImageViewerTest.exe: 0xC0000005: Access violation reading location 0x0000000000000000. This exception is raised on Release x64 mode: Unhandled exception at 0x00007FFAE6D7A478 (ucrtbase.dll) in OpenCVImageViewerTest.exe: An invalid parameter was passed to a function that considers invalid parameters fatal. A few StackOverflow questions I came across mentioned something about library mismatches between debug and release versions of OpenCV and its corresponding libraries. However, I checked the Project Properties for my WinRT component for both versions, and the Additional Libraries I specified are the right versions. OpenCVImageOpener.h: #pragma once // OpenCV Dependent Libraries #include #include #include // WinRT Dependent Headers #include #include #include #include // OpenCV Namespace using namespace cv; namespace OpenCVImage { // Have this class be compiled as a WinRT Component for a UWP app public ref class OpenCVImageOpener sealed { public void loadImage(Platform::String^ filename); // Loads image and displays it on the screen }; }; OpenCVImageOpener.cpp: // Microsoft Visual Studio friendly includes #include "pch.h" // C++ Standard Libraries #include #include #include #include #include #include #include // Windows Runtime Component libraries #include #include // Custom Header Files #include "OpenCVImageOpener.h" // Namespaces using namespace OpenCVImage; using namespace cv; using namespace std; using namespace concurrency; using namespace Platform::Collections; using namespace Windows::Foundation::Collections; using namespace Windows::Foundation; using namespace Windows::UI::Core; void OpenCVImageOpener::loadImage(Platform::String^ filename) { // Debugging statements omitted for brevity std::wstring filenameBuffer(filename->Begin()); string rawFilenameString(filenameBuffer.begin(), filenameBuffer.end()); Mat image = imread(rawFilenameString.c_str()); imshow("Test image", image); // Error occurs right here } The UWP app that calls this code is simply one screen with one button and an event listener.

Error msg intalling opencv Python on window

$
0
0
Hi ,I am new to OpenCV. I am trying to install opencv-python for Windows. I literally followed instruction from this link: https://docs.opencv.org/3.2.0/d5/de5/tutorial_py_setup_in_windows.html When I execute "import cv2" from my python IDLE I got the following error message ImportError:DLL lload failed: %1 is not a valid Win32 application Could anybody help? Thanks, JP

opencv cmake issue

$
0
0
I used to compile from vc12 or msvstudio12 2013,, i like using vc12 because it only needs the basic files, like msvcp120.dll and msvcr120.dll in which in could be run or open from windows XP. so, that's the reason why I used vc12 only. I compiled win32 or x86 with opencv 3.4.0 in vc12 and it has a good result. BUT I did not include opencv_DNN because it also cause an error, it can't build opencv_world340. NOW, I can't compile opencv2.4.13.5 with opencv_world, because I know with opencv_world will have only 1 DLL file, so it's neat. I can't compile because of this following reason, and btw I came from cmake website but I don't find forum to help me with this: ====================== Configuring done CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjpeg" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libpng" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libtiff" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjasper" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "IlmImf" that is not in the export set. Can someone expert here, make changes or edit the cmake file to I could get the opencv_world from opencv2.4.13.5 I think this is the cmake file that errors, ========= OpenCVGenPkgconfig.cmake from opencv2.4.13.5 cmake folder. Do you have any idea that I can make this compilation possible?

How do I find a vertical line in a image?

$
0
0
My current project is to use OpenCV and a webcam to follow a line with the Lego Mindstorm EV3. That would be black tape on a light background. I have a test image (white left, black right) that I can process. The idea is to use moments to find the x location of the vertical line. I can process my test image with cvtColor, GaussianBlur, threshold, erode, dilate, findContours and drawContour. The white region is seen as a block bounded by the edges of the frame. I can create a black border on the contour image to remove the frame edges. Then I am left with a vertical line. FindContours should find the line. But, findContours is area based and I am trying something that is line based. If I findContours of the vertical line, I go back to the edges. What is the contour of a line? I get three contours. 1 left edge and line. 2 line. 3 right edge and line. I could just use the second contour, but that will not expand to a real image with an unknown number of contours. My idea is to find the x location of the vertical line with moments. I can get the average x location of all the moments, but that is misleading and inaccurate. Or, will I have to use BondingRect. My problem is with OpenCV. Does anyone know OpenCV well enough to suggest a valid approach to solve this problem?

How to warp image with predefined homography matrix in OpenCV?

$
0
0
I am trying to set predefined values to homography and then use function warpPerspective that will warp my image. First i used findHomography function and displayed result: H = findHomography(obj, scene, CV_RANSAC); for( int i=0; i(i,j)); } } warpPerspective(image1, result, H, cv::Size(image1.cols + image2.cols, image1.rows)); This works as it is supposed to and i get these values ![image description](/upfiles/15189826514267077.jpg) After that i tried to set values for H and call warpPerspective like this: H.at(0, 0) = 0.766912; H.at(0, 1) = 0.053191; H.at(0, 2) = 637.961151; H.at(1, 0) = -0.118426; H.at(1, 1) = 0.965682; H.at(1, 2) = 3.405685; H.at(2, 0) = -0.000232; H.at(2, 1) = 0.000019; H.at(2, 2) = 1.000000; warpPerspective(image1, result, H, cv::Size(image1.cols + image2.cols, image1.rows)); And now i get System NullReferenceException, do you have any idea why is this failing?

How can i use mask created by background substraction algorithm to see the foreground image as in the video.

$
0
0
I have used the back ground substraction algorithm to create a mas k of moving object now i need to crop the actual image showing only moving object and save it in pc. How can it be done. winName= "Movement Indicator" fgbg = cv2.createBackgroundSubtractorMOG2() while(True): ret, frame= cam.read() height , width =frame.shape[:2] videoMasked =fgbg.apply(frame) #cv2.imshow('fgmask',frame) cv2.imshow('fgmask',videoMasked) if cv2.waitKey(1)==13: break cam.release() cv2.destroyAllWindows()

Integrate OpenCV with Sikulli

$
0
0
Hi, Is it possible to integrate OpenCV with Sikulli? I have an image which detected a button with MSER method. And i want to use that image with that button to increase the size of the button with Sikuli. So is it possible to integrate OpenCV MSER with Sikuli? Or do i have to do it in a separate way? Thanks. Rita Maia

Training and Test images must be of equal size! OpenCV Crash iOS

$
0
0
I am using the fisher face recognizer. When I call the predict function the app crashes. This is what it says in the logs... Face DetectedOpenCV(3.4.0-dev) Error: Bad argument (Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 12000000 elements, but got 1296.) in predict, file /Users/Name/Desktop/OpenCVBuild/opencv_contrib/modules/face/src/fisher_faces.cpp, line 140 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.0-dev) /Users/Name/Desktop/OpenCVBuild/opencv_contrib/modules/face/src/fisher_faces.cpp:140: error: (-5) Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 12000000 elements, but got 1296. in function predict (lldb) My training test images are the same size (3000x4000). What is the problem and how would I fix it?

How to run background process for accessing camera and image processing with OpenCV in Android?

$
0
0
I have learned how we can do image processing in Android with Open-CV but normally we have to extend Activity for doing so. I have gone through the 15-Puzzle Sample Game, is there a way where we can extend this code as Service and run in background.

Saving Clusters in OpenCV

$
0
0
I'm using OpenCV with Python 3.6. Suppose I have this [this black-white binary image](https://i.stack.imgur.com/j2paS.png), which shows 10 white blobs on a black background. Is it possible to save each blob as a separate image file (for a total of 10 files)? For example, the top-left blob would save as [this](https://i.stack.imgur.com/pcdyZ.png). Note that in the example, only the top-left blob is showing. I know that clustering, masks and ROI are things in OpenCV, but I'm unsure how to use them to save each cluster automatically. Apologies if there's already a duplicate answer; I'm new to computer vision and might be searching up the wrong terms!

Why do we get different predictions when using java and python(dnn)?

$
0
0
When using the python language at the output of a neural network, I get an array consisting of numbers from 0 to 5. For example: ...[3 3 3 ... 1 1 1] [3 3 3 ... 1 1 1] [3 3 3 ... 1 1 1]... When using the same model in java, I get the following: -26.287221908569336, -14.588539123535156, -7.386473655700684, 1.4765703678131104, 15.550891876220703. Initially, the data comes in a 4d array from which I get values ​​using the reshape function(see [this](http://answers.opencv.org/question/175676/javaandroid-access-4-dim-mat-planes/)).

Using ORB image recognition

$
0
0
Hello, I have to create a traffic sign detector (in python)which detect,distinguish three sort pf panels (turn right,left ,stop) and show the distance between the vehicle and the sign. I don't know how to do it, like what function can I use. Thanks in advance

How can i set mouse callbacks to different windows with python

$
0
0
I am working on a project that will require me to have two OpenCV windows,i want to set callbacks for the different windows,how do i go about it using python

Template matching not finding all image occurrences

$
0
0
I am not getting 100% result in template matching. If the match pertcentage is 95, it will not show all the target image found. It will show few matches and skip others. I checked the area that missed, it is absolutely similar. sharing code and output.

How to do Nightly Build to the OpenCV for Windows?

$
0
0
I'm new to this OpenCV Library. I would like to know **how to do the nightly building process** for the *Opencv* code in *windows*. I have been checking with this to work on? But i don't get any information's on this one. So, please it will be helpful for me, if someone could have answers for this one? Thanks in Advance....

Function to find joint probability and conditional probability in OpenCV

$
0
0
Is there any built-in function to find Joint Probability and Conditional Probability of images in OpenCV! What does the function "CalcProbDensity" does? OpenCV documentation explanation says divide one histogram by other histogram. Can someone give a bit more elaborate explanation?
Viewing all 4615 articles
Browse latest View live