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

What are realistic processing times for object tracking

$
0
0
Good day, I'm new to the word of image recognition and computer vision. Can someone perhaps give me an indication if it would be possible to speed up video processing for object tracking? To be more clear - Can I fast forward the video to analyze the footage so that a 2 hour video is processed in 30 minutes? System specs: Windows OS with OpenCV making use of the CPU only (i7), 2 M pixel video footage of 2 hours. Would this even be possible when using Linux and GPU? Thanks!

identical object detection

$
0
0
Hey, i'm new to openCV and to learn a bit about it computer vision I'm currently doing an internship at a company that whant's to integrate vision in their machines. **The project**: Detect a little bag and determine it's position using vision while it lay's in it's primairy packaging (black crate). I've added a picture of the bags below. In practice, there will be hunderds of these bags in one crate. ![image description](/upfiles/16007785715108561.jpeg) I've already tried several functions from openCV like gaussian/bilateral filter (see below). I know the lighting causes a bit of a problem (reflection) but I'm going to fix that with a filter or indirect lighting. ![image description](/upfiles/16007787787561811.jpg) **The problem** is that i'm just not able to get a full contour of each bag. The gaussian and bilateral filters are able to smooth out the bags thus removing the little dots inside it, but is also removes the contours of the bags causing them to blend in with each other. **My question** is, are there any solutions for this problem, or is this the wrong approach for this kind of problem, is template matching or a distance camera (bags are 3 tot 5 mm thick) more suitable for this problem? I've tried a little template matching program but without succes because the bags blend in with each other. I'm all ear for different idea's and tips

Detect objects even though they touch the border of an image

$
0
0
Hello to everyone, It is my first post. I am new to image recognition and opencv. I am trying to detect pills from an image and I achieved detect most of them. However, some pills touch the border of the image and I have an issue that my algorithm consider the pill with the circle border as one. Please, there is any solution to this problem. I have not find any. Best regards.

Poor Rectification Results After Good(?) Intrinsic/Extrinsic Parameter Estimation

$
0
0
**Problem**: I have been trying to calibrate 4 cameras to use for 3D reconstruction in our lab but my results so far aren't great. **Physical Setup Details**: The cameras are mounted to the ceiling of the lab and spaced in an arc. My camera pairs have a large baseline ranging from 1.2m --> 1.4m, they are also angled to point at a focal point near the centre of my desired capture volume. The cameras are 1440x1080 (4:3), frame rate is currently set to 60FPS, synchronisation of the cameras relative to a master camera has been tested and verified to be within 6us. **Software Details**: As far as I can tell my intrinsic parameters estimation with calibrateCameraCharuco is good. I am generally getting a root mean square pixel reprojection error of less than 0.5 for each camera. Also, visual inspection of the undistorted images shows no visible distortion. Next, when I calibrate the stereo pairs with stereoCalibrate I get OK results with an rms pixel reprojection error of about 0.9. Inspection of the translation matrix matches the setup in the lab fairly well. My problems begin when I attempt to use stereoRectify to obtain the projection/fundamental matrices for triangulation. My results from stereoRectify are mostly black, and show a lot of warping. In the next sections here I will show my results at each stage. **calibrateCameraCharuco Method/Results**: Here is a snippet of my code to show how I am using the functions provided in OpenCV::aruco. Results are from 100 images. for(int i = 0; i < nFrames; i++) { int r = calibPositions.at(i); // interpolate using camera parameters Mat currentCharucoCorners; vector < int > currentCharucoIds; aruco::interpolateCornersCharuco(FD.allCorners[r], FD.allIds[r], FD.allImgs[r], charucoboard, currentCharucoCorners, currentCharucoIds); CD.allCharucoCorners.push_back(currentCharucoCorners); CD.allCharucoIds.push_back(currentCharucoIds); CD.filteredImages.push_back(FD.allImgs[r]); } // Create imaginary objectPoints for stereo calibration WP.objPoints = charucoboard->chessboardCorners; if(CD.allCharucoCorners.size() < 8) { cerr << "Not enough corners for calibration" << endl; } // calibrate camera using charuco cout << "Calculating reprojection error..." << endl; double repError_all = aruco::calibrateCameraCharuco(CD.allCharucoCorners, CD.allCharucoIds, charucoboard, FD.imgSize, CP.cameraMatrix, CP.distCoeffs, CP.rvecs, CP.tvecs, CD.stdDevInt, CD.stdDevExt, CD.repErrorPerView, CALIB_RATIONAL_MODEL, TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 1000, 1e-8)); cout << "Reprojection error for all selected images --> " << repError_all << endl; cout << "Calculating reprojection error based on best of calibration images (remove if repErr > thresh)..." << endl; int count = 0; for (int i = 0; i < nFrames; i++) { if (CD.repErrorPerView.at(i,0) > 0.8) { CD.allCharucoCorners.erase(CD.allCharucoCorners.begin() + i); CD.allCharucoIds.erase(CD.allCharucoIds.begin() + i); CD.filteredImages.erase(CD.filteredImages.begin() + i); cout << "Removed frame [ " << i << " ] due to poor reprojection error" << endl; count++; } } cout << count << " frames removed." << endl; CD.repError = aruco::calibrateCameraCharuco(CD.allCharucoCorners, CD.allCharucoIds, charucoboard, FD.imgSize, CP.cameraMatrix, CP.distCoeffs, CP.rvecs, CP.tvecs, CD.stdDevInt, CD.stdDevExt, CD.repErrorPerView, 0, TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 1000, 1e-8)); cout << "Reprojection error for best " << nFrames - count << " images --> " << CD.repError << endl; Here is an example of my distorted and undistorted results. [distCoeffs_undistort.png](/upfiles/16007323096963141.png) [distCoeffs_undistort2.png](/upfiles/16007323461037769.png) Here are two of the intrinsic parameter .xml files that I save after calibration. intrinsic calibration file 1: "Mon Sep 21 19:42:02 2020"14401080033
d
8.0605929943849583e+02 0. 7.3480865246959092e+02 0. 8.1007034565182778e+02 5.1757622494227655e+02 0. 0. 1.
15
d
-3.4978195544034996e-01 1.2886581503437988e-01 -1.9665200615673575e-04 -1.4983018383788354e-03 -2.2248879341119590e-02
3.5456431830182816e-01 intrinsic calibration file 2: "Mon Sep 21 19:35:48 2020"14401080033
d
8.0465978952959529e+02 0. 7.0834198622991266e+02 0. 8.0757265281475566e+02 4.9114869480837643e+02 0. 0. 1.
15
d
-3.6701403682828881e-01 1.5425867184023750e-01 6.9635465447631670e-05 -7.6979877001017848e-04 -3.2360458909053834e-02
3.7534224198836619e-01 **stereoCalibrate Method/Results** Here is a snippet of my code to show how I am using the functions provided in OpenCV. Results are from 100 images. cout << "Loaded images..." << endl; vector < int > currentCharucoIds_0, currentCharucoIds_1; vector < Point2f > currentCharucoCorners_0, currentCharucoCorners_1; vector < int > Vec_currentCharucoIds; Mat Vec_currentCharucoCorners; aruco::interpolateCornersCharuco(FD.first.allCorners[r], FD.first.allIds[r], currImgGray_0, charucoboard, currentCharucoCorners_0, currentCharucoIds_0); aruco::interpolateCornersCharuco(FD.second.allCorners[r], FD.second.allIds[r], currImgGray_1, charucoboard, currentCharucoCorners_1, currentCharucoIds_1); aruco::interpolateCornersCharuco(FD.first.allCorners[r], FD.first.allIds[r], currImgGray_0, charucoboard, Vec_currentCharucoCorners, Vec_currentCharucoIds); // need to [0] [1] [2] --> [a,b,c,d; ...;...;] auto result_0 = std::remove_if(boost::make_zip_iterator( boost::make_tuple( currentCharucoIds_0.begin(), currentCharucoCorners_0.begin() ) ), boost::make_zip_iterator( boost::make_tuple( currentCharucoIds_0.end(), currentCharucoCorners_0.end() ) ), [=](boost::tuple const& elem) { return !Match(boost::get<0>(elem), currentCharucoIds_1); }); currentCharucoIds_0.erase(boost::get<0>(result_0.get_iterator_tuple()), currentCharucoIds_0.end()); currentCharucoCorners_0.erase(boost::get<1>(result_0.get_iterator_tuple()), currentCharucoCorners_0.end()); auto result_1 = std::remove_if(boost::make_zip_iterator( boost::make_tuple( currentCharucoIds_1.begin(), currentCharucoCorners_1.begin() ) ), boost::make_zip_iterator( boost::make_tuple( currentCharucoIds_1.end(), currentCharucoCorners_1.end() ) ), [=](boost::tuple const& elem) { return !Match(boost::get<0>(elem), currentCharucoIds_0); }); currentCharucoIds_1.erase(boost::get<0>(result_1.get_iterator_tuple()), currentCharucoIds_1.end()); currentCharucoCorners_1.erase(boost::get<1>(result_1.get_iterator_tuple()), currentCharucoCorners_1.end()); cout << "Calculating matches..." << endl; int matches; if (currentCharucoIds_0.size() == currentCharucoIds_1.size()) { matches = currentCharucoIds_0.size(); cout << matches << " matches" << endl; } else { cout << "ID's not matched correctly, or not enought ID's" << endl; exit(EXIT_FAILURE); } if (currentCharucoCorners_0.size() == currentCharucoCorners_1.size()) { cout << "Adding current corners for cameras to charuco data..." << endl; CD.first.allCharucoCorners.push_back(currentCharucoCorners_0); CD.first.allCharucoIds.push_back(currentCharucoIds_0); CD.first.filteredImages.push_back(currImgGray_0); CD.second.allCharucoCorners.push_back(currentCharucoCorners_1); CD.second.allCharucoIds.push_back(currentCharucoIds_1); CD.second.filteredImages.push_back(currImgGray_1); vector < Point3f > objPoints; vector < int > objPoints_id; objPoints = charucoboard->chessboardCorners; for (unsigned int i = 0; i < charucoboard->chessboardCorners.size(); i++){ objPoints_id.push_back(i); } auto result_3 = std::remove_if(boost::make_zip_iterator( boost::make_tuple( objPoints_id.begin(), objPoints.begin() ) ), boost::make_zip_iterator( boost::make_tuple( objPoints_id.end(), objPoints.end() ) ), [=](boost::tuple const& elem) { return !Match(boost::get<0>(elem), currentCharucoIds_0); }); objPoints_id.erase(boost::get<0>(result_3.get_iterator_tuple()), objPoints_id.end()); objPoints.erase(boost::get<1>(result_3.get_iterator_tuple()), objPoints.end()); WP.first.objPoints.push_back(objPoints); } else { nBadFrames++; cout << "Refined corners/ID count does not match or count is less than 8" << endl; cout << currentCharucoCorners_0.size() << endl; cout << currentCharucoIds_0.size() << endl; } } cout << "Completed interpolation on " << count - nBadFrames << " images. "<< endl; cout << "Beginning stereo calibration for current pair..." << endl; Mat repErrorPerView; double rms = stereoCalibrate(WP.first.objPoints, CD.first.allCharucoCorners, CD.second.allCharucoCorners, intParam.first.cameraMatrix, intParam.first.distCoeffs, intParam.second.cameraMatrix, intParam.second.distCoeffs, Size(1440,1080), extParam.rotation, extParam.translation, extParam.essential, extParam.fundamental, repErrorPerView, CALIB_USE_INTRINSIC_GUESS | CALIB_FIX_FOCAL_LENGTH | CALIB_FIX_PRINCIPAL_POINT | CALIB_FIX_K1 | CALIB_FIX_K2 | CALIB_FIX_K3 | CALIB_FIX_K4 | CALIB_FIX_K5 | CALIB_RATIONAL_MODEL, TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 1000, 1e-8)); cout << repErrorPerView << endl; //cout << "Reprojection error for best " << numFrames - badFrames << " images --> " << rms << endl; cout << rms << endl; Mat Q; // in stereo calib make struct Transformation {Rect and Proj} stereoRectify(intParam.first.cameraMatrix, intParam.first.distCoeffs, intParam.second.cameraMatrix, intParam.second.distCoeffs, FD.first.imgSize, extParam.rotation, extParam.translation, intParam.first.rectificationMatrix, intParam.second.rectificationMatrix, intParam.first.projectionMatrix, intParam.second.projectionMatrix, extParam.dispToDepth, 0, -1, FD.first.imgSize, &intParam.first.regionOfInterest, &intParam.second.regionOfInterest); Mat rot0, rot1, trans0, trans1, cameraMatrix0, cameraMatrix1; decomposeProjectionMatrix(intParam.first.projectionMatrix, cameraMatrix0, rot0, trans0); decomposeProjectionMatrix(intParam.second.projectionMatrix, cameraMatrix1, rot1, trans1); cout << "Camera 1: " << endl << "Rotation: " << endl << rot0 << endl << "Translation: " << endl << trans0 << endl; cout << "Camera 1: ROI H: " << endl << intParam.first.regionOfInterest.height << " W: " << intParam.first.regionOfInterest.width << endl; cout << "Camera 2: " << endl << "Rotation: " << endl << rot1 << endl << "Translation: " << endl << trans1 << endl; cout << "Camera 2: ROI H: " << endl << intParam.second.regionOfInterest.height << " W: " << intParam.second.regionOfInterest.width << endl; Mat map1_1, map1_2, map2_1, map2_2; initUndistortRectifyMap(intParam.first.cameraMatrix, intParam.first.distCoeffs, intParam.first.rectificationMatrix, intParam.first.projectionMatrix, Size(1440,1080), CV_16SC2, map1_1, map1_2); initUndistortRectifyMap(intParam.second.cameraMatrix, intParam.second.distCoeffs, intParam.second.rectificationMatrix, intParam.second.projectionMatrix, Size(1440,1080), CV_16SC2, map2_1, map2_2); Mat img1, img2; // Images to be read Mat img1u, img2u; // Undistorted Imgs Mat img1r, img2r; // Rectified Imgs Mat img1u_Resize, img2u_Resize; // Undistorted resize Mat img1r_Resize, img2r_Resize; // Rectified resize Mat imgCombined, imgCombined_Resize; // Combined result for epilines for (unsigned int i = 0; i < FD.first.allImgs.size(); i++) { img1 = FD.first.allImgs[i]; img2 = FD.second.allImgs[i]; undistort(img1, img1u, intParam.first.cameraMatrix, intParam.first.distCoeffs); undistort(img2, img2u, intParam.second.cameraMatrix, intParam.second.distCoeffs); remap(img1, img1r, map1_1, map1_2, INTER_LINEAR); remap(img2, img2r, map2_1, map2_2, INTER_LINEAR); hconcat(img1r, img2r, imgCombined); // draw horizontal line for(int j = 0; j < imgCombined.rows; j += 16 ) { line(imgCombined, Point(0, j), Point(imgCombined.cols, j), Scalar(0, 255, 0), 1, 8); } Size zero (0, 0); resize(img1u, img1u_Resize, zero, 0.25, 0.25, INTER_LINEAR); resize(img2u, img2u_Resize, zero, 0.25, 0.25, INTER_LINEAR); resize(imgCombined, imgCombined_Resize, zero, 0.25, 0.25, INTER_LINEAR); imshow("Undistorted 1", img1u_Resize); imshow("Undistorted 2", img2u_Resize); imshow("imgCombined", imgCombined_Resize); char key = waitKey(); cout << "q/Q to quit, enter to see next image." << endl; if ( key == 'q' || key == 'Q') { break; } } Here is an example of the output from decomposeProjectionMatrix, I'm not sure if it is correct and it may be causing an issue. pair1 rms=0.463218 Camera 1: Rotation: [1, 0, 0; 0, 1, 0; 0, 0, 1] Translation: [0; 0; 0; 1] Camera 1: ROI H: 0 W: 0 Camera 2: Rotation: [1, 0, 0; 0, 1, 0; 0, 0, 1] Translation: [0.8238847064740386; 6.715809563857897e-18; -4.940656458412465e-324; 0.5667574352738454] Camera 2: ROI H: 0 W: 0 pair2 rms=0.783253 Camera 1: Rotation: [0.9999999999999999, 0, 0; 0, 0.9999999999999999, 0; 0, 0, 1] Translation: [0; 0; 0; 1] Camera 1: ROI H: 760 W: 1440 Camera 2: Rotation: [0.9999999999999999, 0, 0; 0, 0.9999999999999999, 0; 0, 0, 1] Translation: [0.766146582958673; -8.866293832486486e-17; 0; 0.6426658645211748] Camera 2: ROI H: 932 W: 830 pair3 rms=0.760754 Camera 1: Rotation: [1, 0, 0; 0, 1, 0; 0, 0, 1] Translation: [0; 0; 0; 1] Camera 1: ROI H: 0 W: 0 Camera 2: Rotation: [1, 0, 0; 0, 1, 0; 0, 0, 1] Translation: [0.8221122187051663; -6.908022583387919e-17; -0; 0.5693254779611295] Camera 2: ROI H: 0 W: 0 Here is an example of the rectified image pairs. camera pair 1 ![rectified pair 1](/upfiles/16007880456100954.png) camera pair 2 ![rectified pair 2](/upfiles/16007880252527507.png) camera pair 3 ![rectified pair 3](/upfiles/16007880654798975.png) Basically what I am wondering is if there is any issue with my physical setup or code. Would it be better to use a different approach? This is getting quite long so I can post any other information if needed. Thanks for the help!

Chessboard Calibration DBL_EPSILON error

$
0
0
When using videos of my ChArUco chessboard for camera calibration I get the following error on some of my video frames when passing my data to aruco::calibrateCameraCharuco. Error: modules/calib3d/src/calibration.cpp:1211: error: (-215:Assertion failed) fabs(sc) > DBL_EPSILON in function 'cvFindExtrinsicCameraParams2' Can anyone help me figure out what is wrong and if there is a conditional statement or something I can use to fix this?

Assertion Failed ( fabs(sc) > DBL_EPSILON ) using aruco::calibrateCameraCharuco

$
0
0
When I try to calibrate my cameras intrinsic parameters I get the following error when using aruco::calibrateCameraCharuco: modules/calib3d/src/calibration.cpp:1211: error: (-215:Assertion failed) fabs(sc) > DBL_EPSILON in function 'cvFindExtrinsicCameraParams2' What I have noticed is that it seems only certain frames cause this issue. I have taken a couple different calibration videos, however, I only get this error when trying to calibrate with one video in particular. Also, it seems that only certain frames cause this issue. When I set my VideoCapture object to a specific frame past the one that causes this error the function proceeds without any issue. I have calibrated a couple other cameras with different videos and I've had success. Does anyone know what is causing this issue and what a solution may be? If needed I can post some snippets of my code and possibly try to find one of the exact frames that is causing this error.

Error importing cv2 after compiling OpenCV from source (Python)

$
0
0
Hello guys, I am following two tutorials on Youtube on how we can compile OpenCV (4.4.0) from source using CMake and Visual Studio 2019. And currently, I'm using Windows with CUDA 10.1. Tutorial 1: https://www.youtube.com/watch?v=_fqpYLM6SCw&t=331s&ab_channel=TheAIGuy Tutorial 2: https://www.youtube.com/watch?v=tjXkW0-4gME&t=1s&ab_channel=TheCodingBug After following step by step, including "Build" for the ALL_BUILD and "INSTALL" it, I couldn't use the OpenCV in the terminal, by importing python Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2' I also noticed that after obtaining OpenCV.sln, I do not have the "binding" folder like both of tutorial videos. ![image description](/upfiles/16007900821085366.png) ---------------------------------------- The questions are: 1) Does the binding file is really that important ? 2) If its not that important, how can I use the openCV that has been compiled with my Python?

Where can i find the source code implementation of cv::Laplacian()

$
0
0
This may be my inexperience showing but all the other functions that I've searched for were fairly easy to find if I know the module. But for the laplacian even though it is in the imgproc module i can't seem to find the actual source code. How is this function different? I've tried searching for it in the github repository and the closest i got to some implementation is in: opencv/3rdparty/carotene/src/laplacian.cpp But I can't find where any of the functions in this implementation are called, or even where they connect to the cv::Laplacian() call.

Imread with preallocated data pointer (cuda unified memory) is reallocating with the exact same size, but shouldn't

$
0
0
Hello!
I have a problem with processing a set of images using opencv and cuda Unified Memory.
I am trying to use a Mat created once using a pre-allocated data buffer with cudaMallocManaged. When reading the image, the data seem to be reallocated during the mat::create in the imread function, but create should not be re-allocating since my previous data pointer has the exact same size. Here's an example of my issue #include #include #include #include #include #define COLS 5344 #define ROWS 4016 namespace fs = std::experimental::filesystem; int main(int argc, char const *argv[]) { int index = 0; //---- get arguments ---- if (argc < 2) { std::cout << "number of arguments invalid" << std::endl; std::cout << "1 - Input Folder" << std::endl; std::cout << "2 - Output Folder" << std::endl; exit(1); } std::string input_folder = argv[1]; std::string output_folder = argv[2]; // Unified pointers void *src_ptr, *dst_ptr; if (cudaSuccess != cudaMallocManaged(&src_ptr, ROWS*COLS*3)) return -1; cv::Mat src(ROWS, COLS, CV_8UC3, src_ptr); cv::cuda::GpuMat d_src(ROWS, COLS, CV_8UC3, src_ptr); if (cudaSuccess != cudaMallocManaged(&dst_ptr, ROWS*COLS*3)) return -2; cv::Mat dst(rows, cols, CV_8UC3, dst_ptr); cv::cuda::GpuMat d_dst(rows, cols, CV_8UC3, dst_ptr); for (const auto& entry : fs::directory_iterator(input_folder)) { std::cout << "Before imread : src total = " << src.total() << " src elemsize = " << src.elemSize() << " src_ptr : " << src_ptr << " &(src 0 0)" <<&src.at(0, 0) << std::endl; // Reading image src = cv::imread(entry.path()); std::cout << "After imread : src total = " << src.total() << " src elemsize = " << src.elemSize() << " src_ptr : " << src_ptr << " &(src 0 0)" <<&src.at(0, 0) << std::endl; // Some action on cuda device cv::cuda::rotate(d_src, d_dst, d_dst.size(), 180.0); // write output file std::string out_name = output_folder + "preprocessed_image" + std::to_string(index) + ".jpg"; index++; cv::imwrite(out_name, dst); break; // only the first one is needed for the example } return 0; } With this example, when the imread is perform (so a mat create), the data pointer is reallocated for the first loop. It seems weird since mat create should verify mat::total * mat::elemsize, and not reallocate if the result is the same as what is read in the image. And here this is the case. I'm printing the addresses of src_ptr and the data address of the src mat : before the imread, they are identical, after the imread, the second one changed.
My goal is to avoid explicit data transfer between host and cuda device. I really don't know why the data pointer is reallocated, i'm looking forward to some advice in order to correct this issu or avoid it. Thank you in advance.

knnMatch/BFHamming bug or not?

$
0
0
I tried to test various OpenCV keypoint matching methods to find image shift and rotation between two not exactly same images (slices of 3D dataset that may not be perfectly aligned). I found this problem: when two images have the same number of keypoints, matches2points_nndr function copied from https://github.com/thorikawa/akaze-opencv/blob/master/akaze/akaze_utils.cpp does not reduce number of matches and estimateAffinePartial2D returns very low number of inliers and sometimes fails. This problem happens all the time with ORB detector with limited number of keypoints and it happens with other detectors/descriptors randomly, because number of keypoints usually differ. I also tried to use match instead of knnMatch with some sorting for ORB with no success. Am I doing something wrong? I can't believe that ORB method usually fails (unless target number of keypoint is set very high and never reached) and no one reported bug to OpenCV. And AKAZE fails using parts of it's example code. My code including test images is here: https://github.com/pavel-perina/cv-bug Output looks like this (tested in OpenCV 3.3.0 and 4.4.0): ALGORITHM="ORB2500" Image=25; keypoints=2500vs2500; matches=2500; inliers=41 (1.64%) Image=26; keypoints=2500vs2500; matches=2500; inliers=28 (1.12%) Image=27; keypoints=2500vs2500; matches=2500; inliers=38 (1.52%) ALGORITHM="AKAZE" Image=25; keypoints=1670vs1673; matches=1224; inliers=1217 (99.4281%) Image=26; keypoints=1673vs1673; matches=1673; inliers=69 (4.12433%) Image=27; keypoints=1673vs1688; matches=1189; inliers=1176 (98.9066%) AKAZE has very low number of inliers between slices 25&26.

can't find QuasiDenseStereo in opencv_contrib_python

$
0
0
Hi everyone, It's very possible I'm overlooking something, but I can't seem to find the Quasi Dense Stereo implementation in opencv_contrib for python. It's part of the `stereo` module in contrib. Using python3.6 on 64-bit linux, just recompiled the whl file to make sure that quasi_dense_stereo.{cpp,hpp} are getting processed, which it is. But I can't find it in the python module. I've made sure the `import cv2` picks the correct version, the one that I just compiled, but there's no QuasiDenseStereo class anywhere in the module. Any thoughts? Thanks! 1. List item

no such module in import on Xcode with cocoapod OpenCV2

$
0
0
after successfully installed cocoapod 'OpenCV2', set the $(inherited) flag in Xcode Target settings then 'pod update' and opened the project.xcworkspace, the import 'OpenCV2' statement in Xcode resulted in no such module 'OpenCV2'. Xcode Project Navigator is listing 'OpenCV2' under Pods. I am able to import additional installed cocoa pods (e.g. 'SwiftyZeroMQ5'. The 'no such module error for OpenCV2 is also occurring when I install only OpenCV2 cocoapod. Xcode Version: 11.7 MacOs: 10.15.6 Please Help. Thanks a lot.

H265 Performance

$
0
0
Hello, I am using OpenCV 4.4 on a Mac and attempting to write a video in H265 format. It seems that OpenCV writer is very slow compared to FFMPEG conversion. How can I ensure that the writer is using Lossless compression. What flags I should to maximize the performance of writing the video in H265. How can I use flags similar to FFMPEG? Can I use CUDA for H265? Thanks

H265 ffmpeg parameters

$
0
0
If I use ffmpeg codes to write H265 using VideoWriter then how can I pass optional parameters available in ffmpeg to the VideoWriter?

cv:imwrite Python error with Windows: can't open file for writing: permission denied

$
0
0
Hello, I am receiving an error message when I execute the code in Python with Windows10. ```` [ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\imgcodecs\src\loadsave.cpp (710) cv::imwrite_ imwrite_('C:/Users/Default/Pictures/hall.jpg'): can't open file for writing: permission denied ```` The directory initially had an special character "César": "C:\Users\César". But I also tried to save the picture in another location: "C:\Users\Default\Pictures" and the error message still continues. Could somebody help ?

What's the pseudocode or algorithm inside solvePnP's SOLVEPNP_ITERATIVE flag?

$
0
0
Recently, For one of my research paper, I need to know pseudocode or algorithm inside **solvePnP**'s `SOLVEPNP_ITERATIVE` flag which is based on the **Levenberg-Marquardt optimization**. Is there any to find it? Please help. Thanks in advance.

Measuring of lanes or stripes on noisy and underexposed images

$
0
0
I've got a task of measuring of lanes or stripes on severely varied, often noisy and underexposed images using C++. The example ot the input image and of what should be measured is below: [An example of what should be measured on images provided][1] I've tried a couple of approaches using OpenCV so far. The first one basically consisted of the next steps: Filtering, background substruction -> adaptiveThreshold -> thinning -> HoughLinesP -> and then filtering and merging of lines. Please see the llustration image below: [The first attempt result][2] The second approach comprised of search for the beginnings of short stripes with SURF and movement to the left and up along long lines. Please see the llustration image below, note that SURF was done on the original halftone image: [The second attempt result][3] The third approach I've tried: doing the Fourier transform for frames - image fragments (a 4-dimensional matrix is obtained), then finding basic patterns using PCA. Got this result below: [The third attempt result][4] Not sure what to do with that PCA output. Have tried to select lines using adaptiveThreshold using original image, then teach the multilayer perceptron based on this threshold and the PCA result so that it would yield "refined" threshold. An attempt was made to select the parameters resulting in a cleared threshold for further treatment - it works occasionally, but the result is very unstable. **Unfortulately all the approaches above work only with few selected "good" images.** I presume that the ML approach would be the way to go. Unfortunately I have only few images for learning. I would greatly appreciate any suggestions on moving forward to solving this task. Some test source images can be found here: github.com/aliakseis/detect-lines/tree/master/images [1]: https://i.stack.imgur.com/9xoXn.jpg [2]: https://i.stack.imgur.com/eExZX.jpg [3]: https://i.stack.imgur.com/afC1a.jpg [4]: https://i.stack.imgur.com/iANNX.jpg

detect pixel difference in gray scale image

$
0
0
![image description](/upfiles/16009410253523529.png) I have convert image to gray scale image and the result in shown below. is there a way to detect the difference between the tow sections, or separate them ? thanks in advance.

Opencv.js - findPerspective returns wrong corners coordinates

$
0
0
Hi, I'm trying to implement AKAZE with opencv.js and opencv-wasm. Here is my code: const { cv, cvTranslateError } = require('opencv-wasm'); const Jimp = require('jimp'); const util = require('./util.js'); (async () => { try { console.log("Enter 1"); const jimpSrc = await Jimp.read("./images/how_to_play.png"); const jimpSrcToMatch = await Jimp.read("./images/scene.png"); console.log("Enter 2"); // initiate ORB detector, default number of features to retain is 500, bit too low let akaze = new cv.AKAZE(); let img1 = await cv.matFromImageData(jimpSrc.bitmap); let img2 = await cv.matFromImageData(jimpSrcToMatch.bitmap); let res = new cv.Mat(); let mask1 = new cv.Mat(); let mask2 = new cv.Mat(); console.log("Enter 3"); cv.cvtColor(img1, img1, cv.COLOR_BGRA2GRAY, 0); cv.cvtColor(img2, img2, cv.COLOR_BGRA2GRAY, 0); // find descriptors and keypoints with AKAZE detector let kp1 = new cv.KeyPointVector(); let kp2 = new cv.KeyPointVector(); let des1 = new cv.Mat(); let des2 = new cv.Mat(); akaze.detectAndCompute(img1, mask1, kp1, des1); akaze.detectAndCompute(img2, mask2, kp2, des2); // create BFMatcher object and and match descriptors let matcher = new cv.BFMatcher(); let matches = new cv.DMatchVectorVector(); let filteredMatches = new cv.DMatchVector(); matcher.knnMatch(des1, des2, matches, 2); // filter matches for (let i = 0; i < matches.size(); ++i) { let match = matches.get(i); let dMatch1 = match.get(0); let dMatch2 = match.get(1); if (dMatch1.distance <= dMatch2.distance * 0.7) { filteredMatches.push_back(dMatch1); } } cv.drawMatches(img1, kp1, img2, kp2, filteredMatches, res); util.saveMat(res, "matcher-output.png"); if (filteredMatches.size() > 13) { let objectPoints = []; let scenePoints = []; for (let i = 0; i < filteredMatches.size(); ++i) { let dMatch = filteredMatches.get(i); objectPoints.push( new cv.Point(kp1.get(dMatch.queryIdx).pt.x, kp1.get(dMatch.queryIdx).pt.y)); scenePoints.push( new cv.Point(kp2.get(dMatch.trainIdx).pt.x, kp2.get(dMatch.trainIdx).pt.y)); } let homography = cv.findHomography( cv.matFromArray(objectPoints.length, 3, cv.CV_32F, objectPoints), cv.matFromArray(scenePoints.length, 3, cv.CV_32F, scenePoints), cv.RANSAC, 3); let sceneCorners = new cv.Mat(4, 1, cv.CV_32FC2); //let objCorners = cv.matFromArray(4, 1, cv.CV_32FC2, [0, 0, img1.cols - 1, 0, img1.cols - 1, img1.rows - 1, 0, img1.rows - 1]); let objCorners = new cv.Mat(4, 1, cv.CV_32FC2); console.log("Transforming object corners to scene corners..."); // cv.perspectiveTransform(objCorners, sceneCorners, homography); var view = objCorners.data32F; view[0] = 0; view[1] = 0; view[2] = img1.cols; view[3] = 0; view[4] = img1.cols; view[5] = img1.rows; view[6] = 0; view[7] = img1.rows; cv.perspectiveTransform(objCorners, sceneCorners, homography); var dataAns = sceneCorners.data32F; var x1 = new cv.Point(dataAns[0], dataAns[1]); var x2 = new cv.Point(dataAns[2], dataAns[3]); var x3 = new cv.Point(dataAns[4], dataAns[5]); var x4 = new cv.Point(dataAns[6], dataAns[7]); cv.line(res, x1, x2, new cv.Scalar(0, 0, 0), 10, cv.LINE_AA, 0); cv.line(res, x2, x3, new cv.Scalar(0, 0, 0), 10, cv.LINE_AA, 0); cv.line(res, x3, x4, new cv.Scalar(0, 0, 0), 10, cv.LINE_AA, 0); cv.line(res, x4, x1, new cv.Scalar(0, 0, 0), 10, cv.LINE_AA, 0); } } catch (err) { console.log(cvTranslateError(cv, err)); } })(); The problem is, that final corners coordinates x1, x2, x3, x4 are always like 1.00007678, 0.9999767623, -0.9878787.... Any ideas why? P.S I'm well familiar with opencv for Java and Python.

Why imread is reallocating data buffer

$
0
0
Hello! I recently ask an other question similar to this one. Here I don't have any CUDA dependencies : I create a Mat using a pre-allocated data buffer. Here's a code example : #include #include #include #include namespace fs = std::experimental::filesystem; int main(int argc, char const *argv[]) { // ---- get arguments ---- if (argc < 2) { std::cout << "number of arguments invalid" << std::endl; std::cout << "1 - Input Folder" << std::endl; std::cout << "2 - Output Folder" << std::endl; exit(1); } std::string input_folder = argv[1]; std::string output_folder = argv[2]; int cols = 5344, rows = 4016; //your image size cv::Vec3b *src_ptr = (cv::Vec3b *)malloc(rows*cols*sizeof(cv::Vec3b)); cv::Mat src(rows, cols, CV_8UC3, src_ptr); std::cout << src_ptr << " " << src.ptr() << " " << src.size() << std::endl; for (const auto& entry : fs::directory_iterator(input_folder)) { src = cv::imread(entry.path()); std::cout << src_ptr << " " << src.ptr() << " " << src.size() << std::endl; } return 0; } I have an input folder with a set of images, and I am printing the address of the buffer alongside the current address of the data of Mat src. (Also with the size to prove that it is the same). When running it, the address of src data change, and if you have more than one image, you can see that imread reallocate data at the same address every two images. Imread is supposed to call Mat::create : it should not reallocate if it is the same size! I tried another test : cv::Mat temp; In the for loop : temp = cv::imread(entry.path()); temp.copyTo(src); Here the right pre-allocated address is used. I'm looking to avoid this copy and directly use imread. Why does it behave like this? Thanks in advance for any answers!!!
Viewing all 41027 articles
Browse latest View live


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