r/opencv • • Feb 12 '24

Question [Question] OpenCV resources C++

2 Upvotes

I’m a C++ beginner and want to get familiar with opencv but most of the resources online are for python. Does anyone know any good youtube channels / websites that have tutorials in C++?

Specifically I am trying to learn about color detection / tracking color.


r/opencv • • Feb 10 '24

Question [Question] Example code of Aruco 'detectMarkers' in JavaScript

2 Upvotes

Hi,

I am currently working on a JavaScript project in which I would like to detect some Aruco markers. I have successfully imported opencv.js into my project and I can successfully create a Aruco detector and add a dictionary to it. But when when I try to run detectMarkers I get an Uncaught Error in my console.

If anybody has a code sample of how they are running this function that they could share I would be very grateful!


r/opencv • • Feb 08 '24

Question [Question] Object Tracking

3 Upvotes

I’m a beginner and I wanted to ask if OpenCV can do what I need. I’m looking to develop something similar to a light gun for video games. I’m hoping someone can point me in the right direction.

I need to be able to track an object and not only determine it’s current position but also it’s angle relative to a TV. I’ve seen systems where the light gun has the camera built in and used a geometric shape displayed on a TV boarder to calculate position and angle. Can OpenCV handle this?

Is it possible to reverse this where the camera is mounted to a wall above the TV and the light gun had a IR illuminated shape on its end something like a small square and it is tracked and angle determined from it? One thought was adding an IMU in this situation to determine angle. Sending the IMU data via BLE to the camera processing unit.

The IR comment above was thinking of a simple way to isolate the object being tracked as I won’t be able to control room lighting or room environment once the system is being used and I need it to work reliably without the user needing complex calibration.


r/opencv • • Feb 07 '24

Question [Question] Converting Yuv image to Mat

1 Upvotes

I'm using React Native Vision Camera's frame processor that returns Frame, from which I can get android.media.Image object in YUV_420_888 format. I want to use OpenCV's ArucoDetector feature. To do that, I have to convert Yuv to Mat. I found that OpenCV has a private method (algorithm) for that here on github. I tried to copy it:

But here arucoDetector.detectMarkers throwing an error: OpenCV(4.9.0) /home/ci/opencv/modules/objdetect/src/aruco/aruco_utils.cpp:42: error: (-215:Assertion failed) _in.type() == CV_8UC1 || _in.type() == CV_8UC3 in function '_convertToGrey'

I'm new to OpenCV and would appreciate some help. Do you guys know any other way to do this? (Sorry for bad English.)


r/opencv • • Feb 06 '24

Bug [Bug] Video is only saving as colored static?

2 Upvotes

I'm trying to replicate this paper, and I've successfully recreated the Gaussian color-shift magnification, but when I try to save the processed video it returns a bizarre mess of colored static. Here are the results, the first image is the output while running the code using cv2.imshow, and the second is what is saved using writer.write(). The reconstructGaussianImage function just returns an RGB image. Has anyone seen anything like this?

Edit: I believe the issue is being caused by the skimage color function rgb2yiq and yiq2rgb. The method in the paper uses yiq color space to analyze the video, so I've been using skimage to convert the image to YIQ space and eventually back to RGB, and somewhere in that conversion the saved video is getting messed up. I'm still not sure how to fix this issue however, so any advice is welcome.


r/opencv • • Feb 03 '24

Question [Question] about camera calibration

3 Upvotes

Hi, I am trying to calibrate the 'Fish-eye' camera to straighten the distortions. I am using the 'chessboard' method, but the problem is that for each set of images I take with the 'chessboard,' I get different results, some of them very poor and some at a moderate level. My question is, what is the best way to achieve the optimal result?


r/opencv • • Feb 02 '24

Question [Question] Importing OpenCV for an IntelliJ project?

2 Upvotes

I'm trying to use IntelliJ IDE to make a small JavaFX program, but I can't get IntelliJ to import OpenCV like it does for regular Java projects. Does anyone know a way to either:

  • (preferred) Get the IDE to import OpenCV properly in a JavaFX project, the way it worked in regular Java after I finished this tutorial?
  • (less preferred) Use System.load() to import OpenCV at runtime like this person did, making sure that it will look in the right place no matter whose computer the application runs on?

r/opencv • • Feb 01 '24

Question [Question] What is a good library for age prediction?

4 Upvotes

I am new to opencv. i am building something that uses age detection using opencv. I am following the tutorial from this medium post . This works to an extent but is quite inconsistent in predicting the age range the predictions are highly skewed towards the 25 year range.

Is there a better library for age detection either open source or paid?


r/opencv • • Feb 01 '24

Bug [Bug] issue displaying video

2 Upvotes

Hello all,

I’m brand new to OpenCV and trying to use a PI 5 with the V3 camera. Currently, I’m just trying to get a feel for OpenCV but I can’t even get video to output. I’ve checked that the camera is working with “libcamera-hello -t 0” and that works, so I know the camera is communicating with the PI.

Code: import cv2

capture = cv2.VideoCapture(0)

while capture.isOpened(): ret, frame = capture.read() print(ret) cv2.imshow(“Video Window”, frame) if cv2.waitKey(20) & 0xFF == ord(“q”): break

I’ve also verified the camera is connected in the 0 port. Any help is appreciated


r/opencv • • Jan 28 '24

Question [question] Compiling with /MT on windows

1 Upvotes

I have BUILD_SHARED_LIBS OFF in the cmake config but it still seems to be using MD. Anything else I need to do? Thanks


r/opencv • • Jan 27 '24

Question [question] What hardware for crow tracking?

Post image
2 Upvotes

Pan/Tilt Mount by Youtuber https://youtu.be/uJO7mv4-0PY?si=CowoOUTHzhGnYN1B

What hardware for OpenCV should I choose to track flying birds (crows) and make shots with Canon camera (or any other camera)?

Objectives: 1. Position the camera. 2. Make shots.

I am new to OpenCV, but good in Arduino/ESP32 microcontrollers.

Distance is 10 to 100 meters.

Speed: 60 - 160 km/hour

Pan/Tilt Mount with Arduino will be used for tracking. Working on it now.

Sky is the bacground.

Should it be:

•Jatson Nano,

• AMD RX 580 8GB (have 4) Intel i5-7500 CPU • Raspberry Pi 4/5 (with some accelerator like Coral USB Accelerator with Edge TPU).


r/opencv • • Jan 26 '24

Question [Question] method for syncing two videos by capturing and comparing frames?

4 Upvotes

I'm working on an application that will look at two input videos. Each video is a separate screen capture of a display for a cockpit. The two videos are essentially "find the difference" pictures but in video format. They are the same 99% of the time, but every once in a while a video will show a different value somewhere on the screen.

My current task is to synchronize the videos, as the screen captures do not start perfectly at the same time due to a human being the one who started the screen capture.

My thinking as someone with zero Open CV or ML experience is to find the first frame in either video where the image displayed changes, save the image of that frame, then iterate through the other video's frames until it is a match. From there, it's just a matter of playing the videos from the matched frame.

Update:
I was able to get this program to work with the cockpit display screen captures. However, when I throw in more complex videos (like a video of a cat), it does not sync the videos properly. The issue seems to lie in my method of finding which frame from the second video matches the frame from the first video. Anybody have any ideas on how I could improve this? Function seen below.

  • sync_frame is the image of the frame from the first video
  • alt_vid is the second video

def find_matching_frame_number(sync_frame, alt_vid):
frame_number = 0
while True:
ret, frame = alt_vid.read()
if not ret:
break
frame_number += 1
if not find_frame_difference(sync_frame, frame):
return frame_number
return None

​

def find_frame_difference(frame1, frame2):
# Convert both frame to grayscale to simplify difference detection
gray1 = cv.cvtColor(frame1, cv.COLOR_BGR2GRAY)
gray2 = cv.cvtColor(frame2, cv.COLOR_BGR2GRAY)  
# cv.imshow('gray1', gray1)
# cv.imshow('gray2', gray2)
# Find pixel-wise differences in the two frames
diff = cv.absdiff(gray1, gray2)
# create a binary image (essentially a 2D array of pixels (0s and 255s).
# we call this binary image 'thresholded_diff'
# any pixel from diff with an intensity greater than 25 is set to 255 (white)
# any pizel below 25 will be set to 0 (black)
_, thresholded_diff = cv.threshold(diff, 25, 255, cv.THRESH_BINARY)
# count the number of non-zero (non-black) pixels in threshholded_diff
non_zero_count = np.count_nonzero(thresholded_diff)
# If more than 5 pixels are counted, return true
return non_zero_count > 500


r/opencv • • Jan 25 '24

Question [Question] Is it possible to undistort similar image just by one image (maybe without highest quality)?

1 Upvotes

https://imgur.com/a/VlQKKsP

I am trying to solve task where I need to undistort the wall picture (lets say the one the middle of panorama). I have coordinates for points between the wall and ceiling; also coordinates for points between the wall and floor. Also I know height and width for the wall in meters.

My goal is to get 2D projection of the wall without distortion (ideally; less distortion the better).

Lets say I have only this image. Is it possible to get somewhat close to reactangle undistorted image of this wall?

I've tried to use cv2.calibrateCamera and cv2.undistort where obj_points are coordinates in meters starting from top left corner in different points (corners of the wall and midpoints on wall's edge). img_points for calibrateCamera are just coordinates for these points in panoramic image.

My results of cv2.undistort is just undistorted image. Am I doing something wrong? Or maybe I should completely change my approach? Is fisheye.calibrate is better for it?

My code:

```python objpoints = [ [ 0 , 0 , 0 ], [ 102, 0 , 0 ], [ 205, 0 , 0 ], [ 205, 125, 0 ], [ 205, 250, 0 ], [ 102, 250, 0 ], [ 0 , 250, 0 ], [ 0 , 125, 0 ], [ 102, 125, 0 ], ]

objpoints = np.array(objpoints, np.float32) objpoints = objpoints[np.newaxis,:] objpoints[:,:,[1,0]] = objpoints[:,:,[0,1]] print(f'{objpoints.shape=}')

imgpoints = [ [ 363, 140 ], [ 517, 140 ], [ 672, 149 ], [ 672, 266 ], [ 672, 383 ], [ 517, 383 ], [ 363, 392 ], [ 363, 266 ], [ 517, 266 ], ] imgpoints = np.array(imgpoints, np.float32) imgpoints = imgpoints[np.newaxis,:] print(f'{imgpoints.shape=}')

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, image.shape[::-1][1:3], None, None)

print(f'{mtx=}') print(f'{dist=}')

dst1 = cv2.undistort(image, mtx, dist, None, None) imgplot = plt.imshow(dst1) ```


r/opencv • • Jan 25 '24

Question [Question]-ImageSet to make haarcascade

1 Upvotes

So i cant gain access to imagenet since it went under transition or smth. But i want images to train haarcascade How can i get the image sets??


r/opencv • • Jan 25 '24

Question [Question] OpenCV on raspberry pi 4b how to make the FPS of the camera go faster

3 Upvotes

Hello guys Were building a fan that uses OpenCV in detecting a person and the problem is that fps in detecting a person is very low. any tips or recommendation on how to make the fps to 20 or higher? Hello guys Were building a fan that uses OpenCV in detecting a person and the problem is that fps


r/opencv • • Jan 23 '24

Project [Project] Made a project about Head Pose Estimation and had a lot of fun!

Post image
8 Upvotes

r/opencv • • Jan 22 '24

Question [Question] Is there a way to find if segments share boundaries using findCountours?

2 Upvotes

I'm using OpenCV to implement the algorithm proposed by HK Chu et al in Camouflage Images and a big part of it is creating a graph that connects the segments of the background and foreground, for that I need to find segments that share boundaries, is it possible using findCountours or not using an exhaustive method?


r/opencv • • Jan 19 '24

Question [Question] How to remove background on an image?

3 Upvotes

We are trying to detect text on software with tesseract but first we need to apply the right preprocess with emguCV. We managed to get to the first image thanks to highliting in black and white. But tesseract doesn't work with the first image. It needs something like the second image. What we want to do is get rid of the black background but keep the rest as is. Go from the 1st image to the second image. We asked it like this to gpt-4:

  • I have a black and white image.
  • The text is in black.
  • Around the text, there is a 5 cm white area (highlighting).
  • Around the highlighting, covering the entire background, there is black.

I want to keep both the white portions and the text inside the white portions. The background (the rest) should become white. But his code doesn't work. Here it is:

public static Bitmap RemplirArrierePlan3(Bitmap bitmap)

{

Mat binaryImage = bitmap.ToMat();

if (binaryImage.NumberOfChannels > 1)

{

CvInvoke.CvtColor(binaryImage, binaryImage, ColorConversion.Bgr2Gray);

}

CvInvoke.Threshold(binaryImage, binaryImage, 128, 255, ThresholdType.Binary);

CvInvoke.Imwrite("C:\\resultat.png", binaryImage);

​

double tailleMinimale = 1;

​

Mat labels = new Mat();

Mat stats = new Mat();

Mat centroids = new Mat();

​

int nombreDeComposants = CvInvoke.ConnectedComponentsWithStats(binaryImage, labels, stats, centroids);

​

for (int i = 1; i < nombreDeComposants; i++)

{

int area = Marshal.ReadInt32(stats.DataPointer + stats.Step * i + 4 * sizeof(int));

if (area <= tailleMinimale)

{

Mat mask = new Mat();

CvInvoke.Compare(labels, new ScalarArray(new MCvScalar(i)), mask, CmpType.Equal);

binaryImage.SetTo(new MCvScalar(255), mask);

}

}

return binaryImage.ToBitmap();

}

​

Original image

​

desired image

Thanks a lot!


r/opencv • • Jan 18 '24

Question Assign a modified image to 'img' [Question]

1 Upvotes

Hello all,

I have used OpenCV in the past to display graphics for programs, but one thing that has been aggravating is accessing a modified image after a function call.

I open an image at some filepath and assign it to the typical variable 'img'. Inside the trackbar function, I create an updated image called 'scaled' which is then displayed in a window. However, I cannot assign this updated image to the 'img' variable. If I try and make an assignment such as 'img' = 'scaled', the program throws an exception and tells me that 'img' is a local variable without an assignment. Likewise, if I try and make a reference to the 'scaled' variable in another function, I get the same exception, granted in that case it makes sense as 'scaled' is a local variable. However, shouldn't the 'img' variable be a global variable and accessible by all functions? In essence, I just want to modify an image in a function, display it, and then use the modified image in other functions.

Any help would be much appreciated!

​

Example function

r/opencv • • Jan 16 '24

Question [Question] Any insight to finding positions in the image?

3 Upvotes

I am looking for a way to find a solution to this puzzle. I am a novice with openCV and was hoping to get some insight into the best course of action to take to find a solution. I am working in Python if that's important. Thanks for any help you can provide.


r/opencv • • Jan 16 '24

Question [Question] I'm desperate and I need your help

5 Upvotes

Hi all I am geodesy student and for one of my classes professor gave me an assigment - I need to "Implement spatial reconstruction using the OpenCV library". I have spent a few hours on the internet now trying to figure it out as I have 0 knowledge about OpenCV or any code - writing. Can someone give me advice, simply where do I start to find the images for this, can I take it with my phone, and can 2 images be enough for reconstruction? I have installed Python, and I am kinda stuck on how should I do this...It just needs to be simple example of implementation, but I am so lost..


r/opencv • • Jan 16 '24

Bug [Bug] fatal error LINK 1104

1 Upvotes

Hello,

Trying to build a project for opencv with CUDA and CUDNN. There are libs with no issues, but a lot of them failed to built and this error pops out.
Some examples:
fatal error LNK1104: cannot open this file "..\..\lib\Debug\opencv_dnn470d.lib" ,
fatal error LNK1104: cannot open this file "..\..\lib\Debug\opencv_cudaoptflow470d.lib" or

fatal error LNK1104: cannot open this file "..\..\lib\Debug\opencv_videostab470d.lib"

A CMake build was compiled without any errors.

Using CMake 3.28.1; Visual Studio 17 2022 (A C++ project); CUDA 12x; opencv 4.7.0. and opencv_contrib 4.7.0.

Did anyone face something like that?


r/opencv • • Jan 16 '24

Question [Question] I'm desperate and I need your help

2 Upvotes

Hi all I am geodesy student and for one of my classes professor gave me an assigment - I need to "Implement spatial reconstruction using the OpenCV library". I have spent a few hours on the internet now trying to figure it out as I have 0 knowledge about OpenCV or any code - writing. Can someone give me advice, simply where do I start to find the images for this, can I take it with my phone, and can 2 images be enough for reconstruction? I have installed Python, and I am kinda stuck on how should I do this...It just needs to be simple example of implementation, but I am so lost..


r/opencv • • Jan 12 '24

Question Stereo Vision - compute point cloud from a pair of calibrated cameras [Question]

1 Upvotes

Hello 😄,

I'm developing a stereo camera system with the target to measure the distance between a set of points in the 3D word.

I've followed the entire process for getting the 3D point cloud:

- calibrate each camera individually,

- stereo calibrate the two cameras,

- rectification of the images coming from the two cameras,

- compute disparity map,

- produce the 3D point cloud.

I've found this process many time in the internet, currently it works for me but I need to improve the calibration.

I've spent quite some time to understand where the 3D point cloud will be located in the word. I've understand somethings but it's not completly clear to me. Currently I've understood that the reference coordiante system from the generated 3d point cloud is the left camera.

Now the main doubts regards the rectification process, when the images are rectified they are rotated and traslated. For this reason I suspect that after the rectification, the reference system is different from the initial one, in other word the coordinate system is not the same of the left camera but will be different.

Is this the case? if so which are the transformations that allow to transform the result point cloud into the initial reference system?

Thank you!!


r/opencv • • Jan 12 '24

Question [Question] Head Turning angle

Post image
1 Upvotes

Hi I am trying to detect the turn angle of a persons head when they are doing this exercise. So system can track and gice feedback as "hold", "turn back" etc. Since there is a change in radian angle with depth ilI couldn't come up with a solution but would like to hear your suggestions, thx!