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

cv::reg::MapperGradShift produce worse result in the given test code

$
0
0
Actually, I have read the official documentation [here](https://github.com/opencv/opencv_contrib/blob/master/modules/reg/samples/map_test.cpp) about class `Map` in opencv to try to use the module `reg`. And This is my test image: [![enter image description here][1]][1] This is my code: #include #include "opencv2/reg/mapshift.hpp" #include "opencv2/reg/mappergradshift.hpp" #include "opencv2/reg/mapperpyramid.hpp" using namespace cv; using namespace std; using namespace cv::reg; Mat highlight1(const Mat src, const Mat t_mask) { Mat srcImg = src.clone(), mask = t_mask.clone(); threshold(mask, mask, 0, 255, THRESH_BINARY_INV + THRESH_OTSU); cvtColor(mask, mask, COLOR_GRAY2BGR); cvtColor(srcImg, srcImg, COLOR_GRAY2BGR); dilate(mask - Scalar(0, 0, 255), mask, Mat(), Point(-1, -1), 1); return srcImg - mask; } int main() { Mat img1 = imread("img.jpg", 0); Mat img2; // Warp original image Vec shift(5., 5.); MapShift mapTest(shift); mapTest.warp(img1, img2); // Register Ptr mapper = makePtr(); MapperPyramid mappPyr(mapper); Ptr mapPtr = mappPyr.calculate(img1, img2); MapShift* mapShift = dynamic_cast(mapPtr.get()); // Display registration result Mat result; mapShift->inverseWarp(img2, result); Mat registration_before = highlight1(img1, img2); Mat registration_after = highlight1(img1, result); return 0; } But as we see, the `registration_after` is even worse than `registration_before`. What's I have missed? This is `registration_before`: ![](https://i.stack.imgur.com/bkn0f.png) This is `registration_after`: ![](https://i.stack.imgur.com/hOWBf.png) [1]: https://i.stack.imgur.com/RuesS.jpg Why I get a worse result? Is it a bug in this module of OpenCV?

lbp cascade training to detect traffic signs

$
0
0
Hello, I'm trying to train a classifier which detects all these kinds of traffic signs. ![image description](https://comps.canstockphoto.com/set-of-road-signs-signboards-clip-art-vector_csp42317268.jpg) I've trained a classifier (9 stages) that detects all these signs, but it also detects other types of signs or background. I got many false detects. Im using 300 cropped images of signs (around 15 for each type of sign) and 5900 neg images of roads, cities(without signs ofc). What Im doing wrong? My parameters: opencv_createsamples.exe -info info.txt -vec vector.vec -w 30 -h 30 opencv_traincascade.exe -data cascade/ -vec vector.vec -bg bg.txt -numPos 300 -numNeg 5900 -numStages 20 -featureType LBP -mode ALL -w 30 -h 30 -precalcValBufSize 2048 -precalcIdxBufSize 2048 -numThreads 4

OpenCV Java How can I find red lined Rectangles from 12 rectangles.

$
0
0
I am running into a very unique problem statement. I have an image which will have 12 led lights and a few out of them will glow as red. After trying out multiple algorithms, I have reached till this stage (See Image Below ) from an RGB image taken from the camera. ![image description](/upfiles/15341441907886611.jpeg) I have reached to this image by applying this algorithms - Mat detectedEdges = new Mat(ImageMat.rows(), ImageMat.cols(), CvType.CV_8UC1); //Imgproc.blur(ImageMatNew, detectedEdges, new Size(3,3)); Imgproc.GaussianBlur(ImageMatNew, detectedEdges, new Size(3,3), 7); Imgproc.Canny(detectedEdges, detectedEdges, 70, 70 * 3, 3, false); Imgproc.adaptiveThreshold(detectedEdges, detectedEdges, 200,Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C , Imgproc.THRESH_BINARY_INV,3, 7); Imgproc.Canny(detectedEdges, detectedEdges, 10, 10 * 7, 7, true); Now From here, I am completely lost. I have searched all over places and tried multiple approaches. So My problem state goes like this; In this Image, there will be always 12 rectangles. Few rectangles will be red single lined eclosed and others will be black double lined eclosed rectangles. I have to find these single lined red enclosed rectangles and their number from top to bottom or bottom to top between 1-12. I was trying with contours but I don't think contours are going to solve my any problem. Because I tried with Contour Area but here I can match the area or even can't approximate the area so that I can iterate from top to bottom. I am stuck in this problem since a week. any slight hint or approach will help me Thanks in Advance.

TypeError: Incorrect type of self (must be 'CascadeClassifier' or its derivative)

$
0
0
Good morning, I am running a simple python code to recognize pedestrians.When I run this code on my ubunutu machine there is no error. it works perfectly However when i run it in my Docker container I get this error. "TypeError: Incorrect type of self (must be 'CascadeClassifier' or its derivative)" I know the container cannot generate a graphical window that's why I comment commands like imshow. But I just need it to detect and not to display anything. Because when they detect something I send an order to my robot to stop. I don't understand why. Can anyone help please? Here is my code : pedestrians_cascade= cv2.CascadeClassifier('/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/client/hogcascade_pedestrians.xml') cap=cv2.VideoCapture('http://192.168.0.132:8080/?action=stream') incr = 0 while True: s = time.time() - start_time while s<=9: s = time.time() - start_time ret, frame=cap.read() #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) bodies = pedestrians_cascade.detectMultiScale(frame) tcpDecision1.stop_start(bodies, frame) #cv2.imshow('frame',frame) k = cv2.waitKey(30) & 0xff if k == 27: break

RPI 3B Protocol 'rtp' not on whitelist 'file,crypto'! OPENCV 3.3.0

$
0
0
Hello. I'm trying to capture udp stream in my **raspberry pi 3 B** , and i faced to problem, can someone suggest what to do? This is error message **Protocol 'rtp' not on whitelist 'file,crypto'!** I've tried such thing, but no results: 1. Install seperatly opencv 3.3.0/3.3.1/3.4.0/3.4.0-dev 2. Rebuilt my ffmpeg to the latest version, then to the previous version 3.3.3, but again nothing changed. In my ubuntu everything works fine. Don't know why raspbian sucks !!! i am using a.sdp file `c=IN IP4 239.1.1.1` `m=video 5600 RTP/AVP 96` `a=rtpmap:96 H264/90000` and in cv.py use this: `cap=cv2.VideoCapture("./a.sdp")`

A naive approach to evaluate exercise performance--- How to make it better?

$
0
0
Hi, I made a small extension of OpenPose with tensorflow. It can detect and evaluate a user's pose while performing an exercise. My ultimate goal is to create a system that can run on mobile devices. Here's the demo on YouTube: https://www.youtube.com/watch?v=TRLYHUn8yJ4 https://www.youtube.com/watch?v=gpA6o7hF57s Description: The text terminal in the middle will send countdown message to user. When the exercise session starts, the window on the right will show real time image of the user. After the capture session is over, the window on the left will show captured images frame by frame and label them with"correct / wrong" labels. Finally the text terminal will show the overall performance of the user. --------------- The movements during a specific exercise should be repeatable and the rthythm should be the same. So I set the time duration to 4.0 sec and separate it by 0.2 sec to get 20 durations. I created 20 corresponding softmax models for these durations. The pose (which is 18 sets of keypoint coordinates) is the input and the output is either 0(correct) or 1(wrong). I trained these models with my own data(each data set have 2000 samples) And the final result is what you've seen in the Demo video. It certainly works and have potential to be transplanted to mobile platforms, but not good enough. The false positive and negative results are quite obvious. So here are my questions: **Did any one created something similar to this?** **How can I make it better with OpenCV techniques like affine transform?** PS:I did studied the "action recognition" systems. But they are too expensive to run on a mobile device.

Cast CvCameraViewFrame to Mat throws Error. What to do instead?

$
0
0
public Mat onCameraFrame(CvCameraViewFrame inputFrame) { Imgproc.cvtColor((Mat)inputFrame, grayscaleImage, Imgproc.COLOR_RGBA2RGB); E/AndroidRuntime: FATAL EXCEPTION: Thread-2912 java.lang.ClassCastException: org.opencv.android.JavaCameraView$JavaCameraFrame cannot be cast to org.opencv.core.Mat at mzx.chn.lanedetection.LaneDetectActivity.onCameraFrame(LaneDetectActivity.java:242) at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:391) at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:350) at java.lang.Thread.run(Thread.java:856)

Convert perspective image into equirectangular image

$
0
0
I am trying to calibrate stereo fisheye lens using opencv fisheye calibration package. I have successfully calibrated cameras. The output image after rectification is perspective. I can't use perspective because of stretching at edges. I want to convert perspective image after rectification to equirectangular image. I am facing problem while implementing this function. Please let me if anyone had already done this. Thanks in advance!

Segmentation of Signature

$
0
0
I need to get just "signature with white background" from the image is like this: ![image description](/upfiles/15342694007219833.png) Could you suggest any image processing algorithms/ways or any Computer Vision, Deep Learning Machine Learning based solutions?

Android studio failed build NDK project: error finished with non-zero exit value 2 on windows

$
0
0
I'm running into this error:> Process 'command 'C:/Users/cvlab/AppData/Local/Android/Sdk/ndk-bundle/ndk-build.cmd'' finished with non-zero exit value 2 This is my gradle file of the project: apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.example.cvlab.myapplication" minSdkVersion 16 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } sourceSets.main { jni.srcDirs = [] //disable automatic ndk-build call } task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') { commandLine "C:/Users/cvlab/AppData/Local/Android/Sdk/ndk-bundle/ndk-build.cmd", 'NDK_PROJECT_PATH=build/intermediates/ndk', 'NDK_LIBS_OUT=src/main/jniLibs', 'APP_BUILD_SCRIPT=src/main/jni/Android.mk', 'NDK_APPLICATION_MK=src/main/jni/Application.mk' } tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn ndkBuild } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0-beta01' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation project(':openCVLibrary330') } Sync, make project and clean project are resulting without any error. How to fix it? Thanks in Advance

opencv error: assertion failed (samples.cols == var_count && samples.type() == 5) in cv::ml:: etc.

$
0
0
I created a xml file by using svm . In my test program i have loaded that xml file and i use svm predict, but it showing the error. how can i correct this ? int main(){ HOGDescriptor hog; vector featureVector; Ptr svm = ml::SVM::create(); Mat testdata, feature; Mat img = imread("C:/Users/Sam/Desktop/Test/1.jpg"); hog.compute(img, featureVector, Size(32, 32), Size(0, 0)); feature = Mat(featureVector).reshape(1, 1); testdata.push_back(feature); svm->load("Features.xml"); svm->predict(testdata); } ![image description](/upfiles/1534498322258621.png)

Difference between FloodFill and Watershed

$
0
0
What is the difference between OpenCV's functions `floodFill()` and `watershed`? I seem to understand that watershed takes some markers and fills from there. But it looks like flood fill does the same thing except it has a mask and seeds (not markers). What is the difference and when is one method better/more applicable than the other?

Are Lens Distortion Coefficients inverted for projectPoints?

$
0
0
Good day guys, I am trying to simulate and image with lens barrel distortion. I create a virtual chessboard (only the corners) and then project it onto my image plane using OpenCV. The idea is to project these points with known distortion coefficients, and then attempt a lens distortion calibration (with `calibrateCamera`), and see if the same coefficients are obtained. **My question** is about the `projectPoints` function which takes `distCoeffs` as an input. Are these coefficients the same that must be used to *undistort* an image (output of `calibrateCamera`)? This means the function will have to calculate the inverse of that operation. Or, does it use those coefficients to distort the object points directly? Meaning that the will not correlate at all at the output of e.g. `calibrateCamera`. I ask, because I noticed my simulation does pincushion distortion when I expect barrel, and vica versa. Which seems that the distortion does the opposite of what I think it does. The minimal working code that I used to simulate the image (in Python): # The distortion matrix that I vary distortion = np.array([0.03, 0.0001, 0.0, 0.0, 0.0001]) # Generate Grid of Object Points grid_size, square_size = [20, 20], 0.2 object_points = np.zeros([grid_size[0] * grid_size[1], 3]) mx, my = [(grid_size[0] - 1) * square_size / 2, (grid_size[1] - 1) * square_size / 2] for i in range(grid_size[0]): for j in range(grid_size[1]): object_points[i * grid_size[0] + j] = [i * square_size - mx, j * square_size - my, 0] # Setup the camera information f, p = [5e-3, 120e-8] intrinsic = np.array([[f/p, 0, 0], [0, f/p, 0], [0, 0, 1]]) rvec = np.array([0.0, 0.0, 0.0]) tvec = np.array([0.0, 0.0, 3.0]) # Project the points image_points, jacobian = cv2.projectPoints(object_points, rvec, tvec, intrinsic, distortion) # Plot the points (using PyPlot) plt.scatter(*zip(*image_points[:, 0, :]), marker='.') plt.axis('equal') plt.xlim((-4000, 4000)) plt.ylim((-4000, 4000)) plt.grid() plt.show() Thank you for your help!

OpenCV Code not doing anything (no output)

$
0
0
I have seemed to have reached an impasse with the current project I am working with. Currently, when I build the project in visual studio code on Ubuntu 16.04 LTS with the LXDE Desktop environment, I'm not getting any errors or output really from the program, it just doesn't seem to really do anything and I don't know why. I'll link the files for someone to look at and if any insight can be offered as to the code or some way I'm supposed to be doing something, I'm definitely open to it, I'd give more details, but I'm getting so little feedback from the console that I pretty much have nothing to give in that regard. The end goal of the program is to dewarp a fisheye lens on a camera if that helps and is based off of the code from this: http://aishack.in/tutorials/calibrating-undistorting-opencv-oh-yeah/ If there's any more information I can provide, let me know, but I'm just stuck since I don't know how to go about diagnosing the issue when I'm getting absolutely no console feedback of any kind. Link to files: https://drive.google.com/open?id=1UT7_R5pAri1lp37QFlpYkhVj4r-YyxiE Camera.json couldn't upload for some reason, so here's that: { "CameraInfo": { "Brand":"SBX", "Model":"D5500", "Lense":"55mm AF-S", "FocalLength": 55, "Aperature": 2.8 }, "CameraMatrix": { "r1c1":"fx", "r1c2":"0", "r1c3":"cx", "r2c1":"0", "r2c2":"fy", "r2c3":"cy", "r3c1":"0", "r3c2":"0", "r3c3":"1" }, "DistortionCoefficients": { } }

Hot to force stitching of very similar images

$
0
0
What is the way to force stitching of very similar images? There are scenarios where similar images should get stitched, yet no matter the configuration it always fails. An example, lets imagine the target is the sea horizon, practically all images will look the same as the next one, but the Stitcher will always discard all the images no matter how low the Confidence Threshold is set. ![image description](/upfiles/15345393895927613.jpg)

What is the concept of Object Recoginition (Image Processing manually from Zero) ?

$
0
0
Hello , i am a student and i have been studying about Computer Vision especially OpenCV with Python 3. Now, i understand about the basic of Image Processing, Computer Vision, and Neural Network with Tensorflow. With CNN (tensorflow), we just give the a lot of original image and let the CNN work by itself (Finding the Pattern, Extract Feature, etc.). So, you can get the object recognition easily. I often read about the Object Recognition with Image Processing manually such as (Convert the Grayscale Image, Image Segmentation, Extract Features, etc.) But.., I don't understand about workflow and concept of Object Recognition with Image Processing manually (of course i don't know about how to programming it, too). I have been searching in Google about Object Recognition with Image Processing manually, but there are a lot of different workflow (like the one use GLCM metod and the one didn't use GLCM method, etc.), so it makes me confused. Can anyone suggest me a reference or website about that , please ? Thanks a lot, God Bless You All #Sorry for my bad grammar

meanshift sample code in C++

$
0
0
In OpenCV tutorial code I only see the code for meanshift in Python. Can you please have the same code somewhere in C++? It will be very useful for the community. https://github.com/opencv/opencv/tree/master/samples/cpp import numpy as np import cv2 cap = cv2.VideoCapture('slow.flv') # take first frame of the video ret,frame = cap.read() # setup initial location of window r,h,c,w = 250,90,400,125 # simply hardcoded the values track_window = (c,r,w,h) # set up the ROI for tracking roi = frame[r:r+h, c:c+w] hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.))) roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180]) cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX) # Setup the termination criteria, either 10 iteration or move by atleast 1 pt term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 ) while(1): ret ,frame = cap.read() if ret == True: hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) dst = cv2.calcBackProject([hsv],[0],roi_hist,[0,180],1) # apply meanshift to get the new location ret, track_window = cv2.meanShift(dst, track_window, term_crit) # Draw it on image x,y,w,h = track_window img2 = cv2.rectangle(frame, (x,y), (x+w,y+h), 255,2) cv2.imshow('img2',img2) k = cv2.waitKey(60) & 0xff if k == 27: break else: cv2.imwrite(chr(k)+".jpg",img2) else: break cv2.destroyAllWindows() cap.release() http://docs.opencv.org/master/db/df8/tutorial_py_meanshift.html

Finding overlap of two objects in an image using OpenCV

$
0
0
I have this image and would like to find the intersection points of the two objects ( blue vector and red vector ). Unfortunately, the find_intersection method between the vectors from the c++ standard library returns a size 0 because ofcourse there in no overlap of the edges where the two objects meet. So, is there an elegant way to find the intersecting part of the blue and the red part using OpenCV? Maybe using findContours or CannyEdge or any convolving filter? I am not sure, how I should proceed.![image description](/upfiles/15345847547694428.png)

How to run my app on another PC?

$
0
0
Hello. I'm using OpenCV 3.3.1 on Windows 7 64-bit and Visual Studio 2017. I want to run my .exe on another PC. On target PC installed Win7(64-bit) but there are no Visual Studio and OpenCV. How to make my application portable? I've tried to place necessary .dll files (**opencv_core331d.dll**, **opencv_highgui331d.dll** and so on) in folder with my .exe file, but it doesnt help. Moreover, I got error about missing **VCRUNTIME140D.DLL** and some others non-opencv libraries. Is there detailed guidance about making OpenCV projects portable? Regards

Optimization for Singleboard PC(like orangePi, RasberryPi...) on linux

$
0
0
Hello. My problem in short: on desktop my application works good, on singleboard PC it freezes. Even with simple video output from webcamera (**imshow()** ) it glitches. I have created application on desktop, it uses USB webcamera and make processing video stream. Parameters of desktop: Win7 64-bit AMD A4-4000(2 cores @3.00GHz) integrated Graphics Radeon HD7480D 8 GB RAM On this PC my application runs without issues (I didnt measure actual FPS value, but video looks smooth enough). My video processing algoritm consumes ~120MB of RAM, CPU loaded at 50%; Also it takes about 70~120 ms per frame for processing. ![image description](/upfiles/1534595264496441.jpg) Goal is to port my algoritm on single board PC. My SBPC: [Sopine](https://www.pine64.org/?page_id=1486) [Parameters](http://wiki.pine64.org/index.php/PINE_A64-LTS/SOPine_Main_Page): CPU: ARM A64 (4 cores @1.1GHz , 64 bit) GPU: ARM Mali400MP2 Dual-core RAM: 2 GB I have tested it on next operation systems: Armbian, Xenial Mate. Even when I tried to show in opencv video output from webcamera, application freezes and CPU load becomes up to 100%. Also, I'm testing web camera output with simple linux application - cheese. On Xenial Mate distributive it shows stream smoothly. My application in "imshow only" mode still freezes. On Armbian both (cheese and my application ) are freezing. I'm not advanced user on Linux, but from my experience with Windows it looks like some drivers are missing. Code is below. Maybe there are some issues with it? In general, it makes HSV selection for specific color and finds coutours with large areas, then prints does object with this color finded or no. **CODE:** void videoProcessing(Mat& camera_input, Mat& original_img){ camera_input.copyTo(original_img); // object color // H: 25 - 90 // S: 0 - 255 // V: 50 - 255 cvtColor(camera_input, camera_input, COLOR_BGR2HSV); //Convert the captured frame inRange(camera_input, Scalar(25, 0, 50), Scalar(90, 255, 255), camera_input); //imshow("camera_ranged", camera_input); // debug: HSV colorspace image //morphological operations erode(camera_input, camera_input, getStructuringElement(MORPH_ELLIPSE, Size(5, 5))); dilate(camera_input, camera_input, getStructuringElement(MORPH_RECT, Size(10, 10))); dilate(camera_input, camera_input, getStructuringElement(MORPH_ELLIPSE, Size(10, 10))); //imshow("camera_morph", camera_input); // debug: morph image vector < vector > contours; findContours(camera_input, contours, RETR_LIST, CHAIN_APPROX_NONE, Point(0, 0)); Mat drawing = Mat::zeros(camera_input.size(), CV_8UC3); for (size_t i = 0; i < contours.size(); i++) { Scalar color = Scalar(121, 113, 96); drawContours(drawing, contours, i, color, -1); //imshow("contour", drawing); // debug: show contours } gl_obj_decected = false; // Find areas vector areas; for (size_t i = 0; i < contours.size(); i++) { areas.push_back(contourArea(contours[i], false)); //printf("--------------contour #%d area:%f\n", i, areas[i]); // debug if (areas[i] >= 40000) { if (counterFound > 3) { gl_obj_decected = true; } } } // prevent bouncing if (counterFound > 3) { if ((gl_obj_decected == true) && (gl_obj_last_state == false)) { printf("[FOUND] Open solenoid...\n"); gl_obj_last_state = true; } else if ((gl_obj_decected == false) && (gl_obj_last_state == true)) { printf("[NOT FOUND] Close solenoid\n"); gl_obj_last_state = false; } counterFound = 0; } counterFound++; if (gl_obj_decected) { // show some text on initial image printVideoOverlay(original_img); } } int main(int argc, char* argv[]){ Mat camera_input, camera_input_orig; VideoCapture cap; //---------------------- int64 e1, e2; // testing clock counts for operations double time; //---------------------- cap.open(0); if (!cap.isOpened()) { cerr << "ERROR! Unable to open camera\n"; system("pause"); //wait for any key press return -1; } cout << "Start grabbing" << endl; for (;;) { cap.read(camera_input); if (camera_input.empty()) { cerr << "ERROR! blank frame grabbed\n"; system("pause"); //wait for any key press return -1; } imshow(camera_live, camera_input); // debug: original capture e1 = getTickCount(); // test algoritm speed videoProcessing(camera_input, camera_input_orig); e2 = getTickCount(); // test algoritm speed time = (e2 - e1) / getTickFrequency(); // test algoritm speed (total time) // exit if (waitKey(5) >= 0) { break; } } } And on [pastenin](https://pastebin.com/h3ieEuL3) 1) Please advices me what should I check about "drivers"? 2) Does it possible to use Mali GPU with OpenCV? If yes, are there some examples of usage? 3) Any glaring mistakes with code? Regards
Viewing all 41027 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>