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

dnn module forward() output in intermediate layers?

$
0
0
Hi, im trying to get the activations from a specific layer using the dnn module. Specifically the forward() method, since that seems to be the only method that does this. If i understand the documentation correctly, the following code should give me the output for every Layer. names = self.net.getLayerNames() outputs = self.net.forward(names) the result is a set of arrays. However, when i look at the values in these arrays they don't seem to be quite right. For example, my 3d layer is a relu layer, which should output max(0,input), but the array contains negative values. So my question is: - **what exactly am i looking at in the forward() output if its not the output of each layer,** - **and how can i get the activations of each layer using the dnn module?**

dnn module getPerfProfile tick output?

$
0
0
I am trying to implement the getPerfProfile to measure the runtime of my nn. [the documentation for getPerfProfile](https://docs.opencv.org/3.4/db/d30/classcv_1_1dnn_1_1Net.html#a06ce946f675f75d1c020c5ddbc78aedc) says that the result is returned in "ticks". There is however no method in python to get or convert ticks, and it is not specified how long a tick is, or how to convert it to a time. - If ticks are the amount of cpu cycles used by the dnn, then they should be the same every time for the same image, and also be CPU agnostic. I've tested this and it is not the case. - If ticks are a unit of time, they should be convertible into different time units. The only unit it could be is nanoseconds, but i can't find any source saying that ticks are measured in nanoseconds in python (or any other time unit) so the question is: what is a tick as specified in the documentation? And if it really is ns, why is that not stated in the documentation?

getFLOPS of deep neural network

$
0
0
[the dnn:Net class](https://docs.opencv.org/3.4/db/d30/classcv_1_1dnn_1_1Net.html#ad0d10b1ff622c89562d2befaf351af45) has a method "getFLOPS", which is supposed to take a vector of shapes for all net inputs (netInputShapes). How do i get this vector from my net? The Method getLayerShapes() also requires a netInputShape but there is no method that actually outputs a Net Layer Shape.

active contour (cvSnakeImage) in OPencv 4

$
0
0
Hello, I want to use active contours, but i can't find them in Opencv 4.1.0, i know that cvSnakeImage existed in modules in the older versions of Opencv, i can't find an answer to question in this forum or in the internet, and thank you.

Why my App crashes when i applied Imgproc.resize

$
0
0
As the illustration shows, now i have the 'original' frame, not fill fully the screen. And i expect to got a fullscreen frame like below part, so i choose using imgproc.resize to achieve this, but when i run my app on the mobilephone, the app quit unexpectedly, i don't know why, anyone can help me ? Thanks ! ![image description](/upfiles/1571560192969201.jpg) Here is some related code: public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { Mat frame = inputFrame.rgba(); Mat dst = new Mat(); Imgproc.resize(frame,dst,new Size(),1.5,1.5,Imgproc.INTER_LINEAR); frame.release(); return dst; } And this is debug error report: E/cv::error(): OpenCV(3.4.7) Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp, line 101 E/org.opencv.android.Utils: nMatToBitmap caught cv::Exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:101: error: (-215:Assertion failed) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function 'void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)' E/CameraBridge: Mat type: Mat [ 1620*2880*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0xffffffffc9934a88, dataAddr=0xffffffffc3100000 ] E/CameraBridge: Bitmap type: 1920*1080 E/CameraBridge: Utils.matToBitmap() throws an exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:101: error: (-215:Assertion failed) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function 'void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)'

MatchTemplate and get matching score or confidence hint

$
0
0
I read the matchtemplate tutorial in the [documenation](https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html) , when i try to find the confidence or matching score , it always return the confidence as 1 , i trace the sample code and found the reason is normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); after commenting the previous line the result is fine . so i think we may need to update the documentation and comment the previouse line of code and here it's my code to get the score or confidence from matchtemplate bool method_accepts_mask = (TM_SQDIFF == match_method || match_method == TM_CCORR_NORMED); if (use_mask && method_accepts_mask) { matchTemplate(img, templ, result, match_method, mask); } else { matchTemplate(img, templ, result, match_method); } //normalize(result, result, 0, 1, NORM_MINMAX, -1, Mat());//new added check double minVal; double maxVal; Point minLoc; Point maxLoc; Point matchLoc; minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat()); double dConfidence; if (match_method == TM_SQDIFF || match_method == TM_SQDIFF_NORMED) { matchLoc = minLoc; dConfidence = 1 - minVal; } else { matchLoc = maxLoc; dConfidence = maxVal; }

Calculating a template matching similarity score?

$
0
0
Hello everyone, I am trying the simple template matching function matchTemplate. However I'm still having a hard time understanding how to extract the "overall" matching coefficient score for the instance. I know that depending on the method used, the coefficient varies 0-1 or -1 to 1 and each pixel is having a similarity index in result matric. But then how do we get an overall similarity score for that matching? I'd really really appreciate your help with this. As I'm stuck in this process and have no one else to ask for help. Thanks a ton!

Converting 2d point to 3d point

$
0
0
I have a fixed camera with known cameraMatrix and distCoeffs. I also have a chessboard which is fixed too, and transform and rotation vector are also calculated using solvePnP. I'm wondering how is possible to get 3d location of a 2d point on the same plane that the chessboard is located. Like the picture below: ![image description](/upfiles/15715816426495417.jpg) One thing for sure is that the Z of that point is 0 but how to get X and Y of that point? I only need mathematics explanation of this projection but it would be great if there was a sample source code too.

Unable to operate 2 arrays due to Assertion failed (type2 == CV_64F && (sz2.height == 1 || sz 2.height == 4)) in cv::arithm_op

$
0
0
I am trying to operate 2 arrays (images) but my code -Opencv by example chapter 6- always crashes due to -I have found - a diffence value in the Mat Array property Step. One of the images -1st frame- comes from a directory and is read with while (images.read(frame))... The other one had been read with light_pattern = imread(samples::findFile(light_pattern_file), 0); When a function is called, to remove light, it crashes because "Sizes of input arguments do not match (The operation is neither 'array op array' ..." Mat removeLight(Mat img, Mat pattern) { Mat aux; // Require change our image to 32 float for division Mat img32, pattern32; img.convertTo(img32, CV_32F); pattern.convertTo(pattern32, CV_32F); // Divide the frame image by the pattern //Sizes of input arguments do not match (The operation is neither 'array op array' aux = 1 - (img32 / pattern32); // Scale it to convert o 8bit format aux = aux * 255; // Convert 8 bits format aux.convertTo(aux, CV_8U); //equalizeHist( aux, aux ); // aux = pattern - img; return aux; } Checking the structure of the input arrays, I found out that their Mat Step value differs. One being {960, 3}, the other one {320, 1}. I have unsuccesfully tried to convert either one to fit the other one. Not possible yet. I would like to know whether I can read(frame) in a way that I get it, similar Step to the one that comes from the imread(file_pattern, 0).

Identifiers switch undefined / defined with not changes on code!

$
0
0
identifiers switch from being properly recognized to suddently throwing E0020 error code "Identifier ... is undefined". I change nothing in the code. I have learned that just adding or deleting blank lines makes the red underlines go away -and so do the warning and error flags- then I can rebuild the project with not errors. It is wierd because I have done not changes to any single line of code to get back to 'normal'. Sometimes just waiting and saving the project does get rid of the undefined flags. I am following Opencv by example exercise 6, as follows: Be aware that I have move libraries to the standard c:/opencv location I have been able to make all the previous 5 exercises just fine. // OpenCV by example - Chapter 6 Classification #include #include #include #include using namespace std; // OpenCV includes #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/ml.hpp" #include "opencv2/MultipleImageWindow.h" using namespace cv; using namespace cv::ml; MultipleImageWindow* miw; Mat light_pattern; Ptr svm=SVM::create(); Scalar green(0, 255, 0), blue(255, 0, 0), red(0, 0, 255); // OpenCV command line parser functions // Keys accecpted by command line parser const char* keys = { "{help h usage ? | | print this message}" "{@image |test.pgm| Image to classify}" }; static Scalar randomColor(RNG& rng) { int icolor = (unsigned)rng; return Scalar(icolor & 255, (icolor >> 8) & 255, (icolor >> 16) & 255); } void plotTrainData(Mat trainData, Mat labels, float* error = NULL) { float area_max, ar_max, area_min, ar_min; area_max = ar_max = 0; area_min = ar_min = 99999999; // Get the min and max of each feature for normalize plot image for (int i = 0; i < trainData.rows; i++) { float area = trainData.at(i, 0); float ar = trainData.at(i, 1); if (area > area_max) area_max = area; if (ar > ar_max) ar_max = ar; if (area < area_min) area_min = area; if (ar < ar_min) ar_min = ar; } // Create Image for plot Mat plot = Mat::zeros(512, 512, CV_8UC3); // HERE THE CV_8UC3 IDENTIFIER ONE OF THOSE THAT MISSBEHAIVES // Plot each of two features in a 2D graph using an image // where x is area and y is aspect ratio for (int i = 0; i < trainData.rows; i++) { // Set the X y pos for each data float area = trainData.at(i, 0); float ar = trainData.at(i, 1); int x = (int)(512.0f * ((area - area_min) / (area_max - area_min))); int y = (int)(512.0f * ((ar - ar_min) / (ar_max - ar_min))); // Get label int label = labels.at(i); // Set color depend of label Scalar color; if (label == 0) color = green; // NUT else if (label == 1) color = blue; // RING else if (label == 2) color = red; // SCREW circle(plot, Point(x, y), 3, color, -1, 8); } if (error != NULL) { stringstream ss; ss << "Error: " << *error << "\n"; putText(plot, ss.str().c_str(), Point(20, 512 - 40), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(200, 200, 200), 1, LINE_AA); } miw->addImage("Plot", plot); }

Converting camera feed into relative intensity in mW

$
0
0
Hi guys, general question here. I think this might have been questioned many times but my searches always end up in some rabbit hole. As per the title, is there an objective way to establish the power intensity in mW of an ROI in a camera feed? I've been using the method to convert the readings from my camera using the mean of the ROI (the code is something like follows:) mean = cv::mean(ROI); But the intensity, as far as I understood it, is relative or in arbitrary units (a.u.). Is the measure of intensity, if need be in mW, the sum of all the pixel intensities in an array ROI? My golden standard is if possible, we can make the measurement comparable to a photodiode or a power meter. How do we link the scalar value with an absolute unit of power? Thanks. Vizier87

How to create trained_classifierNM1(2).xml, OCRHMM_transitions_table.xml files?

$
0
0
Hi Professionals! How to create trained_classifierNM1(2).xml, OCRHMM_transitions_table.xml files? What I am using is useless, cant detect any texts visible, especially for small texts but they are clear to recognize. Please kindly help me Thanks

Getting error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:257 error

$
0
0
Hi, I tried to find the [LBP](https://github.com/arsho/local_binary_patterns/blob/master/lbp.py) on Hyperspectral Image after computing first 3 Principal Component Analysis. I am getting the following error. error Traceback (most recent call last) in () 1 img_bgr=pcdata ----> 2 img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY) error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:257: error: (-2:Unspecified error) in function 'cv::CvtHelper::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<1>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]' Unsupported depth of input image: 'VDepth::contains(depth)' where 'depth' is 6 (CV_64F)

Basic factors to develop an in-house vision inspection system

$
0
0
Hello, I work for a company that is evaluating to start the development of generic vision inspection systems, in-house. We expect to develop around 50 such machines in the next five years. So far we need to explore the basic factors that would lead to success: - When is it justified to develop such systems in-house, as opposed to going with off-the-shelf devices? - What are the skills we should be looking for in developers? - What is the equipment normally used? (lighting, cameras, computer or controller...) The typical tasks we would be doing include: Component presence detection, component recognition, physical measurements, surface inspection, reading bar codes, and finding components in the physical space to guide pick-and-place robots. We work in an industrial environment with production sites spread over the world, so reliability and robustness is something we must consider. As an actual example, one of the applications includes measuring a 50mm, dark circular component which has a tolerance of 0.02mm. How would you go around this problem?

How to save predicted data in opencv?

$
0
0
Hi all, I am working on a project where i need to save the predicted (resulted) data to implement it i.e., people count, age, gender and the face recognized images from camera.

Getting Error: cv2.error: OpenCV(4.1.2) D:\Build\OpenCV\opencv-4.1.2\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

$
0
0
Error: cv2.error: OpenCV(4.1.2) D:\Build\OpenCV\opencv-4.1.2\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' I am getting this error when using the drawMatches function and am not sure what the issue is. Function call: matching_result = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None,flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS) I have tried reinstalling opencv in case my original installation was missing something. I also tried version 4.1.1 and still had no success. Any ideas?

Building OpenCV 4 with CUDA

$
0
0
I am so exited for the [merging](https://github.com/opencv/opencv/pull/14827) of the GSoC project enabling CUDA support in OpenCV! However I am uncertain about the build procedure shown [in this gist](https://gist.github.com/YashasSamaga/a84cf2826ab2dc755005321fe17cd15d). I think I understand setting cmake build options like this: cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_CUDA=ON \ -D WITH_CUDNN=ON \ Where do I set the "following option" > OPENCV_DNN_CUDA then?

cuda optical flow : opencv 4.1.2

$
0
0
Can we use multiple gpus to run nvidia optical flow sdk while creating > NvidiaOpticalFlow_1_0: in Ptr nvof = NvidiaOpticalFlow_1_0::create( frameL.size().width, frameL.size().height, perfPreset, enableTemporalHints, enableExternalHints, enableCostBuffer, gpuId); if yes, then in what format does it take multiple gpu ids for eg in list [0, 1] or dict {0, 1} or something else ?

split screen from two USB cameras

$
0
0
Hi all Really like OpenCV and admire what is possible. For start, would like to make make simple split screen (vertical split) from two usb cameras. I have old 16:9 monitor, rpi 3 and two usb cameras which i would like to use to begin with OpenCV. For start, would like to have them merged and full screened on Raspberry Pi which is connected to monitor. I understand there is so much surveillance software but i want to keep it live view, no recording, and to have it start as fast as possible when i click icon on raspberry, Thanks!

Features Detection with AKAZE for small images, the dimension of the unanalyzed boundary

$
0
0
Hello All, I'm new to OpenCV Answers community. **Situation:** Using the AKAZE to find the key points of a given gray scale image(Dimension 120 x 43), 0 key points were detected. Then I am doing a test with add black margin on each direction **Trails"** add margin on each side of the original image and then do the AKAZE detections. Finding as followed: Original Detected Keypoints: 0 ![image description](/upfiles/15717090266241424.png) Margin **10**, Detected points **3**: ![image description](/upfiles/15717094352390487.png) Margin **15**, Detected points **6**: ![image description](/upfiles/15717095214476053.png) Margin **20**, Detected points **15**: ![image description](/upfiles/15717096393729835.png) We can see there is a trend, more key points were detected when increase the margin. **Question** For the AKAZE, is there any limitation for the image size?
Viewing all 41027 articles
Browse latest View live


Latest Images

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