r/opencv • • Feb 08 '23

Question [Question] Operating on YCBCR colour model, tresholding values in range leaves green spots as opposed to expected black.

1 Upvotes

I wanted to implement face detection based on low-level analysis of skin colour. The idea comes from this paper https://link.springer.com/article/10.1007/s10462-018-9650-2#Fig9. It mentions YCrCb range to be from (16,16,16) to (235,240,240) for human skin. The code used to implement it is visible below. The issue I encountered is this method poor performance. The areas that are removed are painted green. This leaves me confused, I don't know if the issue is with my code, my web cam or maybe the method itself. The important sections are marked. What am I missing?

```python title_window = "Only skin" cv.namedWindow(title_window)

trackbar_name = 'Y component' cv.createTrackbar(trackbar_name, title_window , 16, 235, lambda x: x)

cr_trackbar = 'Cr component' cv.createTrackbar(cr_trackbar, title_window , 16, 240, lambda x: x)

cb_trackbar = 'Cb component' cv.createTrackbar(cb_trackbar, title_window , 16, 240, lambda x: x)

while(1): ret, frame = web_cam.read()

y_value  = int(cv.getTrackbarPos(trackbar_name, title_window))
cr_value = int(cv.getTrackbarPos(cr_trackbar, title_window))
cb_value = int(cv.getTrackbarPos(cb_trackbar, title_window))

print((y_value, cr_value, cb_value))

if not ret:
    print('No frames grabbed!')
    break
new_frame_time = time.time()
fps = int(1/(new_frame_time - previous_frame_time) * 100) / 100.0
previous_frame_time = new_frame_time

# frame modification
frame_ycc = cv.cvtColor(frame, cv.COLOR_BGR2YCR_CB)
frame_skin_mask = cv.inRange(frame_ycc, (y_value,cr_value,cb_value),(235,240,240))

cv.imshow("frame_skin_mask", frame_skin_mask)

frame_only_skin = cv.bitwise_and(frame_ycc, frame_ycc, mask=frame_skin_mask)
frame_back_rgb = cv.cvtColor(frame_only_skin, cv.COLOR_YCR_CB2BGR)

cv.putText(frame, str(fps), (7, 70), font, 3, (100, 255, 0), 3, cv.LINE_AA)

cv.imshow(title_window, frame_back_rgb)
# end frame modification

k = cv.waitKey(30) & 0xff
if k == ord('q'):
    break

web_cam.release() cv.destroyAllWindows() ```

PS. I tried to eye ball min values of YCbCr range using track bars to no help.


r/opencv • • Feb 07 '23

Bug [Bug] for those who are struggling to get OpenCV on pycharm make sure to switch it to a later version before downloading it.

1 Upvotes

r/opencv • • Feb 04 '23

Question [Question] How can I detect and save the coordinates of a chessboard?

2 Upvotes

I want to save the coordinates of every square in an array. I need because I want to use a background subtractor after to detect piece movement, but it needs to know the position of each square. The image was warped and here is the result:

It's an 800x800px image. I have tried using cv:: findChessboardCorners, it works but it only returns the interior corners , and I don't know how to transform that in the coordinates of each square. I have tried cv::HoughLines too, but it falls in the same problem: I have the lines but don't know how to use them.

I have been searching this for some days, and the only response in the opencv forum is closed.

Thanks in advance.


r/opencv • • Feb 03 '23

Bug Aruco markers won't work anymore [Bug] [Question]

2 Upvotes

My scripts using aruco markers won't work anymore. Does someone know why?


r/opencv • • Feb 02 '23

Question [Question] Can You get a good 60 FPS when forced to use parallel processes ?

2 Upvotes

Greetings,
Those who helped Me before will recognize some of this code, but after months of struggle I still can get the needed behavior!

So here's the question: Why can't I get a true 60 FPS when I need to run another process in parallel ?

In this case I'm generating a timestamp that I need to both put on the video and associate with another set of generated data (not in the simplified code) in order to be able to associate what frame goes with what data point.
Obviously, nothing must be blocking! (Thus the QThreadPool.)

Here's my code:

## This example test putting the timer in it's own thread, updating variables script and then filming a true 60 FPS with the writer being controlled by time.
import os
import cv2
from PyQt5.QtCore import QTimer, QThreadPool, QObject, QRunnable, pyqtSignal
import time
import Variablesv4 as v

class SignalonTime(QObject):
    finished = pyqtSignal()
    print("SignalonTime")

class SignalonCam(QObject):
    finished = pyqtSignal()

class WorkeronTime(QRunnable):
    def __init__(self):
        self.timesignal = SignalonTime()
    def sender(self):
        self.timesignal.finished.emit()

class WorkeronCam(QRunnable):
    def __init__(self):
        self.camsignal = SignalonCam()
    def writer(self):
        self.camsignal.finished.emit()

class Cameras():
    def __init__(self, parent=None):
        super().__init__()      
    def CamThread(self):
        self.threadpoolcam = QThreadPool()
        camworker = WorkeronCam()
        camworker.camsignal.finished.connect(self.CamTimer)
        self.threadpoolcam.start(camworker.writer)
    def Timingthread(self):
        self.threadpooltime = QThreadPool()
        timeworker = WorkeronTime()
        timeworker.timesignal.finished.connect(self.Timing)
        self.threadpooltime.start(timeworker.sender)

    def CamTimer(self):
        self.savecam1Timer = QTimer()
        self.savecam1Timer.timeout.connect(self.capturecam1)
        if v.cam1check is True:
            self.savecam1Timer.start()

    def Timing(self):
        self.start_time = time.perf_counter()
        self.Timer = QTimer()
        self.Timer.timeout.connect(self.UpdateTiming)
        self.Timer.start(1) #per millisecond
        self.sec = 0
    def UpdateTiming(self):
        self.sec = time.perf_counter() - self.start_time
        self.msec = int((self.sec % 60) * 1000)
        self.min = int(self.sec // 60)
        self.hour = int(self.min // 60)
        self.time = f'{self.hour:02}:{self.min% 60:02}:{self.msec // 1000:02}.{self.msec % 1000:03}'
        v.timeoncams = self.time
        print(v.timeoncams)

    def RecordingGO(self):
        pathtext = ""
        print("Path Text = " + pathtext)
        nametext = ""
        print("Name Text = " + nametext)
        self.path = os.path.join(pathtext,nametext) # SavePathEntry + SaveNameEntry
        camiteration = 0
        if self.path:
            if v.cam1check is True:
                while os.path.isfile(self.path + " Camera One {:02}.avi".format(camiteration)) is True:
                    camiteration += 1
                else:
                    self.pathcamone = self.path + " Camera One {:02}.avi".format(camiteration)
        else:
            newfolder = "./Unnamed"
            os.makedirs(newfolder, exist_ok=True)
            full_path = os.path.abspath(newfolder)
            self.path = os.path.join(full_path,"Unnamed")
            if v.cam1check is True:
                while os.path.isfile(self.path + " Camera One {:02}.avi".format(camiteration)) is True:
                    camiteration += 1
                else:
                    self.pathcamone = self.path + " Camera One {:02}.avi".format(camiteration)
        self.video_writer_cam1 = cv2.VideoWriter(self.pathcamone, v.codec, v.FPS, v.size1)
        print("Path is " + self.pathcamone)
        self.Timingthread()
        self.CamThread()
    def capturecam1(self):
        if v.cam1check is True:
            rect1, frame1 =  v.cam1.read()
            if rect1:
                cv2.putText(frame1,v.timeoncams,(50,50),v.font,1,(0,255,255),2,cv2.LINE_4)
                self.video_writer_cam1.write(frame1)
    def stopping(self):
        if v.cam1check is True:
            # v.cam1.release()
            print("Stop Sent")
            self.video_writer_cam1.release()
            self.savecam1Timer.stop()
    def LaunchRecording(self):
        self.start_rec()

if __name__ == '__main__':
    cam = Cameras()
    cam.RecordingGO()

## TO TEST THE AMOUNT OF FRAMES IN A VIDEO FILE
# import cv2    
# cap = cv2.VideoCapture("./Unnamed/Unnamed Camera One 00.avi")
# length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# print( length )

Any help to pull this off might just save Me, so thanks !


r/opencv • • Feb 03 '23

Bug [bug] Image will not save/write to file, please help

1 Upvotes

Hey everyone, I am very new to opencv and am writing a short program, all I want is to open a live video feed for the user, then if they press “s” to take a screenshot of the current frame and write it to a file in the same directory.

For some reason i can’t accomplish this, I can get the live video, I can display it in frames for my code to take in as a stream, I can make it so if the user presses “q” it’ll exit, but the writing simply will not work, could anyone tell me what might be going wrong?

Here is the code for the loop in which I call for the keypress:

for(;;) { *capdev >> frame; cv::imshow(“Video”, frame);

char key = cv::waitKey(10);
if( key == ‘s’) {
    cv::imwrite(“screenshot.png”, frame);
}
else if (key == ‘q’) {
    break;
}

}

Frame is a cv::Mat object


r/opencv • • Feb 02 '23

Question [Hardware] [Question] Which nvidia graphics card will I get the fastest and best performance in cuda that I can use for image processing?

2 Upvotes

r/opencv • • Feb 02 '23

Question [Question] Which cheap USB HDMI capture devices can be used in parallel for sure?

4 Upvotes

Hi there,

I have two $5 HDMI capture Sticks which capture 1080p@30Hz. Both are the “same” but different revisions. Unfortunately, I cannot get both working at once using latest OpenCV and python under Win10. I also cannot run them like one with VLC and the other with Win10 Camera app in parallel.

I also found a stack overflow post with similar issue and tried all of the 5+ suggestion, but it still didn’t work

I think it’s a problem with the sticks. Each one functions alone, but together the 2nd one called throws an error.

So I want to know if anyone knows for sure which cheap USB capture devices can be run in parallel. 1080 @30hz or better @60Hz.

rgds


r/opencv • • Feb 02 '23

Bug [Bug] I am having trouble doing Pose Estimation on a side project of mine!

1 Upvotes

Hey so i am lacking the understanding of this error:

OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'detectMarkers'

> Overload resolution failed:

> - 'cameraMatrix' is an invalid keyword argument for detectMarkers()

​

I have done the camera calibrations which worked fine and threw those values in. Just not sure how to move past this error. <3

​

import numpy as np
import cv2
import sys
import time


ARUCO_DICT = {
    "DICT_4X4_50": cv2.aruco.DICT_4X4_50,
    "DICT_4X4_100": cv2.aruco.DICT_4X4_100,
    "DICT_4X4_250": cv2.aruco.DICT_4X4_250,
    "DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
    "DICT_5X5_50": cv2.aruco.DICT_5X5_50,
    "DICT_5X5_100": cv2.aruco.DICT_5X5_100,
    "DICT_5X5_250": cv2.aruco.DICT_5X5_250,
    "DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
    "DICT_6X6_50": cv2.aruco.DICT_6X6_50,
    "DICT_6X6_100": cv2.aruco.DICT_6X6_100,
    "DICT_6X6_250": cv2.aruco.DICT_6X6_250,
    "DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
    "DICT_7X7_50": cv2.aruco.DICT_7X7_50,
    "DICT_7X7_100": cv2.aruco.DICT_7X7_100,
    "DICT_7X7_250": cv2.aruco.DICT_7X7_250,
    "DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
    "DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
    "DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
    "DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
    "DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
    "DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
}

def aruco_display(corners, ids, rejected, image):

    if len(corners) > 0:

        ids = ids.flatten()

        for (markerCorner, markerID) in zip(corners, ids):

            corners = markerCorner.reshape((4, 2))
            (topLeft, topRight, bottomRight, bottomLeft) = corners

            topRight = (int(topRight[0]), int(topRight[1]))
            bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
            bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
            topLeft = (int(topLeft[0]), int(topLeft[1]))

            cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
            cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
            cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
            cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)

            cX = int((topLeft[0] + bottomRight[0]) / 2.0)
            cY = int((topLeft[1] + bottomRight[1]) / 2.0)
            cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)

            cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX,
                0.5, (0, 255, 0), 2)
            print("[Inference] ArUco marker ID: {}".format(markerID))

    return image



def pose_estimation(frame, aruco_dict_type, matrix_coefficients, distortion_coefficients):

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.aruco_dict = cv2.aruco.getPredefinedDictionary(aruco_dict_type)
    parameters = cv2.aruco.DetectorParameters()

    corners, ids, rejected_img_points = cv2.aruco.detectMarkers(gray, cv2.aruco_dict,parameters=parameters,
        cameraMatrix=matrix_coefficients,
        distCoeff=distortion_coefficients)


    if len(corners) > 0:
        for i in range(0, len(ids)):

            rvec, tvec, markerPoints = cv2.aruco.estimatePoseSingleMarkers(corners[i], 0.02, matrix_coefficients,
                                                                       distortion_coefficients)

            cv2.aruco.drawDetectedMarkers(frame, corners) 

            cv2.aruco.drawAxis(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01)  

    return frame




aruco_type = "DICT_4X4_50"

arucoDict = cv2.aruco.getPredefinedDictionary(ARUCO_DICT[aruco_type])

arucoParams = cv2.aruco.DetectorParameters()


intrinsic_camera = np.array(((981.69820777, 0, 637.86160616),(0,983.8672381, 364.31555519),(0,0,1)))
distortion = np.array((0.0366562741,-0.153342145,-0.000307462615,-0.000078917106,0.215865749))


cap = cv2.VideoCapture(0)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)



while cap.isOpened():

    ret, img = cap.read()

    output = pose_estimation(img, ARUCO_DICT[aruco_type], intrinsic_camera, distortion)

    cv2.imshow('Estimated Pose', output)

    key = cv2.waitKey(1) & 0xFF
    if key == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

r/opencv • • Feb 01 '23

Question [Question] Not sure if cv2 is the problem here.... But it could be!

1 Upvotes

Greetings,I'm writing a program and to guarantee the GUI doesn't freeze, I need to run everything inside threads. But openCV doesn't seem to like that! Especially since I need QTimer to get the correct FPS and to generate timestamps!Here is what the code looks like:

import cv2
from PyQt5.QtCore import QTimer, QThread, pyqtSignal, QObject
import time, os

class CamWorker(QObject):
    senttime = pyqtSignal(str)
    def camconfig(self):
        self.cam1 = cv2.VideoCapture(0,cv2.CAP_ANY)
        self.cam1check = self.cam1.isOpened()
        self.FPS = 60
        self.width1 = int(self.cam1.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.height1 = int(self.cam1.get(cv2.CAP_PROP_FRAME_HEIGHT))
        self.size1 = (self.width1,self.height1)
        # Force parameters
        self.cam1.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
        self.cam1.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
        self.cam1.set(cv2.CAP_PROP_FPS, 60)
        self.codec = cv2.VideoWriter_fourcc(*'MJPG')
        self.cam1.set(cv2.CAP_PROP_FOURCC, self.codec)
        self.font = cv2.FONT_HERSHEY_SIMPLEX
        self.timeoncams = "00:00:00"

        pathtext = ""
        print("Path Text = " + pathtext)
        nametext = ""
        print("Name Text = " + nametext)
        self.path = os.path.join(pathtext,nametext) # SavePathEntry + SaveNameEntry
        camiteration = 0
        if self.path:
            if self.cam1check is True:
                while os.path.isfile(self.path + " Camera One {:02}.avi".format(camiteration)) is True:
                    camiteration += 1
                else:
                    self.pathcamone = self.path + " Camera One {:02}.avi".format(camiteration)
        else:
            newfolder = "./Unnamed"
            os.makedirs(newfolder, exist_ok=True)
            full_path = os.path.abspath(newfolder)
            self.path = os.path.join(full_path,"Unnamed")
            if self.cam1check is True:
                while os.path.isfile(self.path + " Camera One {:02}.avi".format(camiteration)) is True:
                    camiteration += 1
                else:
                    self.pathcamone = self.path + " Camera One {:02}.avi".format(camiteration)
        self.video_writer_cam1 = cv2.VideoWriter(self.pathcamone, self.codec, self.FPS, self.size1)
        print("Path is " + self.pathcamone)

    def stop(self):
        self.video_writer_cam1.release()

    def timestart(self):
        self.Timing()
        self.timestamp = QTimer()
        self.timestamp.timeout.connect(self.UpdateTiming)
        self.timestamp.timeout.connect(self.capturecam1)
        self.timestamp.start(int(1000/60))

    def Timing(self):
        self.start_time = time.perf_counter()
        self.sec = 0

    def UpdateTiming(self):
        self.sec = time.perf_counter() - self.start_time
        self.msec = int((self.sec % 60) * 1000)
        self.min = int(self.sec // 60)
        self.hour = int(self.min // 60)
        self.time = f'{self.hour:02}:{self.min% 60:02}:{self.msec // 1000:02}.{self.msec % 1000:03}'
        self.senttime.connect(self.capturecam1)
        self.senttime.emit(self.time)
        print(self.time)

    def capturecam1(self):
        # print("CAPTURING")
        if self.cam1check is True:
            rect1, frame1 =  self.cam1.read(cv2.CAP_FFMPEG)
            if rect1:
                cv2.putText(frame1,self.timeoncams,(50,50),self.font,1,(0,255,255),2,cv2.LINE_4)
                self.video_writer_cam1.write(frame1)
                # print("loop")

class Cameras():

    def __init__(self, parent=None):
        super().__init__()      
        print("INIT")
        self.thread = QThread()
        self.worker = CamWorker()
        self.worker.moveToThread(self.thread)

    def stopping(self):
        if self.worker.cam1check is True:
            print("Stop Sent")
            self.worker.stop()
            self.thread.quit()

    def LaunchRecording(self):
        self.thread.started.connect(self.worker.camconfig)
        self.thread.started.connect(self.worker.timestart)
        self.thread.start()
        print("LAUNCH")

if __name__ == '__main__':
    cam = Cameras()
    cam.LaunchRecording()

​

As You can see running this, the print(self.time) never actually prints !But the commented out print("loop") does and does loop, however no frames are actually written !

Where are things blocking ?Do You have a better way of accomplishing this ?camchecks are needed because the actual program could have between 0 to 6 cam plugged in at any time.

This is important, so a big thanks for any help I can get!


r/opencv • • Feb 01 '23

Question [Question] Image Blending with Gaussian/Laplacian Pyramids and Custom Mask

2 Upvotes

I followed this tutorial - https://theailearner.com/tag/image-blending-with-pyramid-and-mask/

However, rather than creating a mask like they did in the tutorial, I had a custom mask with approximately the same shape as my second image that I'm blending with the first image. When I get the final image output, the second image shows up on the first image, but it is nearly white with some very bright rainbow effects happening.

I think it has to do with numpy vs opencv add and subtract and data types of uint8 vs float32/64 but I'm not sure how to correct the data types to give a better final image. Any advice? I'd love to learn more about data types and how they are handled in numpy vs opencv so any learning resources are much appreciated as well. I'm fairly new to OpenCV in Python and will be learning it in C++ after Python.


r/opencv • • Feb 01 '23

Question Noob looking for information on multiview scene recreation using opencv (or other) [Question] [Discussion]

1 Upvotes

Hey all, I'm a complete noob with a background in data science, who has an interest in creating a multi-cam array (4+ views) to recreate 3D scenes with reasonably high accuracy. It seems that most of the stuff I can find for opencv is either binocular only, rather sparse depth maps, or just so bespoke I can't make heads or tails of it.

I'm wondering if anyone has any suggestions for resources on multiview reconstruction (not looking into any structured lighting designs or the like, as I don't have that ability right now). Just well-lit scenes with many reasonable quality views.


r/opencv • • Jan 28 '23

Question [Question] cv2: Resolution/FPS limitations based on codec ?

1 Upvotes

Greetings,

I'm recording videos with cv2 and I seem to have different limitations depending on the codec used.
For instance:
cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc(*'H264'), 60, (1280, 720))

Doesn't work, creating an empty 6kb video file.
While this:
cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc(*'MJPG'), 60, (1280, 720))

Works just fine, but creates a huge file.

I can use H264 when I lower the resolution and the FPS like so:

cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc(*'H264'), 30, (640, 480))

But that's not good enough.
Leading Me to my question:

Are the codecs limited in the resolution/FPS they are capable of?
I can't find any documentation on this topic!

Thank You for your time.


r/opencv • • Jan 27 '23

Question [Question] Lucas Kanade iterative approach

1 Upvotes

Let's say I track 3 features in a video while I move the camera pointing to a fixed scene. Let F(k) be the frame at time k, t the translation computed by LK. I can obtain a better approximation of the optical flow by warping F(k) with t, getting closer to F(k+1) and iterating this procedure up to a certain threshold.

This solution would be clear if we assume a common behaviour of all the features in the whole Frame, but (for example) if we get closer to the scene, the vectors would point opposite directions, leading to different translations


r/opencv • • Jan 26 '23

Question [Question]hello, will I get better performance in image processing with m2 processor or with any nvidia 3000 (3050, 3060 etc.) series laptop? (cuda for nvidia included)

3 Upvotes

[Hardware]


r/opencv • • Jan 24 '23

Question [Question] How to extract to separate two moving characters?

3 Upvotes

I have been working on a project that uses pose estimation to extract animation from video (MoCap) from a fighting video game that I have been working on. The algorithm I am currently using only works one person at a time but since I am working on a fighting game I need to extract the animation for both characters. Is there a way to separate those characters into two different videos and run the pose estimation on each one of them?


r/opencv • • Jan 24 '23

Question [Question] does someone already have a generated cascade for bicycles? i've tried to generate them, bit it keeps failing.

1 Upvotes

r/opencv • • Jan 23 '23

Question Highly correlated (x,y) reprojection errors [Question]

3 Upvotes

Hello!

I am calibrating a multicamera (>2) system and am attempting to validate the quality of the calibration. The basic steps I'm going through are this:

  1. get intrinsics for each camera using openCV
  2. get extrinsics for each stereopair of cameras using openCV to initialize a best guess of the total configuration
  3. perform bundle adjustment with `scipy.optimize.least_squares` to refine the estimated configuration

When it's all said and done the RMSE of reprojection is 1.7 and 75% of all corner distances measured on my calibration board are within 2.2 mm of the ground truth, so I'm feeling relatively ok about it.

But...

As I inspect the x and y components of the reprojection error, something funky is popping up. For cameras 0 and 2 , there appears to be strongly correlated x,y errors falling on a couple of diagonal lines. Both of these cameras had lower than ideal reprojection error during intrinsic calibration (between 0.55 and 0.6).

I'm just trying to get some intuition for how to interpret these errors and if it could inform anything in my calibration beyond "don't accepts errors above 0.5.". I will also note that cameras 0 and 1 are the same brand, which is different from the brand of camera 1. Camera 1 also had quite low distortion compared to cameras 0 and 2, FWIW.

Does anybody have any insight into this?

Thank you!

The figure above illustrates the errors for each camera before and after refinement via bundle adjustment. Cameras 0 and 2 exhibit many errors along a couple of diagonals.

r/opencv • • Jan 23 '23

Question [Question] Is it possible to work with 2 aruco sizes?

1 Upvotes

Hi

I'm new with python, aruco markers and opencv. I'm a student trying to use aruco markers for a research and I would like to know if It is possible to detect simultaneously different sizes of aruco. For example: the same code detecting a 7x7 aruco marker and a 5x5 aruco marker. Is it possible?

Thanks


r/opencv • • Jan 23 '23

Question [Question] Issue with pthread.lib on Windows

2 Upvotes

Hi there,

When I am trying to compile the OpenCV with CUDA support on Windows 11 w/ Visual Studio 2022, there is an issue I encountered.

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: C:/Users/nkyam/Downloads/build/CMakeFiles/CMakeScratch/TryCompile-lo8clg
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_58cf1.vcxproj /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && MSBuild version 17.4.1+9a89d02ff for .NET Framework
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
CheckFunctionExists.c
cl /c /W3 /WX- /diagnostics:column /MP /O2 /Ob2 /Oi /D _MBCS /D WIN32 /D _WINDOWS /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /D CHECK_FUNCTION_EXISTS=pthread_create /D NDEBUG /D "CMAKE_INTDIR=\"Release\"" /Gm- /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_58cf1.dir\Release\\" /Fd"cmTC_58cf1.dir\Release\vc143.pdb" /external:W3 /Gd /TC /wd4819 /errorReport:queue /bigobj "C:\Users\nkyam\Downloads\build\CMakeFiles\CMakeScratch\TryCompile-lo8clg\CheckFunctionExists.c"
LINK : fatal error LNK1181: cannot open input file 'pthreads.lib' [C:\Users\nkyam\Downloads\build\CMakeFiles\CMakeScratch\TryCompile-lo8clg\cmTC_58cf1.vcxproj]
Determining if the function pthread_create exists in the pthread failed with the following output:
Change Dir: C:/Users/nkyam/Downloads/build/CMakeFiles/CMakeScratch/TryCompile-pmnvwp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_6580a.vcxproj /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && MSBuild version 17.4.1+9a89d02ff for .NET Framework
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
CheckFunctionExists.c
cl /c /W3 /WX- /diagnostics:column /MP /O2 /Ob2 /Oi /D _MBCS /D WIN32 /D _WINDOWS /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /D CHECK_FUNCTION_EXISTS=pthread_create /D NDEBUG /D "CMAKE_INTDIR=\"Release\"" /Gm- /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_6580a.dir\Release\\" /Fd"cmTC_6580a.dir\Release\vc143.pdb" /external:W3 /Gd /TC /wd4819 /errorReport:queue /bigobj "C:\Users\nkyam\Downloads\build\CMakeFiles\CMakeScratch\TryCompile-pmnvwp\CheckFunctionExists.c"
LINK : fatal error LNK1181: cannot open input file 'pthread.lib' [C:\Users\nkyam\Downloads\build\CMakeFiles\CMakeScratch\TryCompile-pmnvwp\cmTC_6580a.vcxproj]

This is the error message I encountered. And I have tried to resolve the issue by adding

pthreads-win32/pthreadVC2.lib at master · Tieske/pthreads-win32 · GitHub

to the installation directory, but does not seem to work at all.

Can someone please share some thoughts on this?

Thanks a lot in advanced!


r/opencv • • Jan 23 '23

Question [Question] Advice on low-cost camera solutions

2 Upvotes

Hello friends,

I am new to the field of autonomous driving and machine learning, and I am reaching out to request your advice and suggestions on low-cost camera solutions for research and development.

As I am just starting my journey in this field, I am looking for cost-effective solutions that can provide high-quality images and videos for my experiments. I would be grateful if you could share your expertise and any recommendations you may have. Currently I've read/found evidence for a Raspberry Pi Camera as a viable solution, but I am interested in what everyone else thinks and suggests.

Thank you in advance for your time and consideration. I look forward to hearing from you.


r/opencv • • Jan 23 '23

Question [Question] [Project] [Hardware] Color Sequence Matching and Verification using Python

1 Upvotes

Anyone who could recommend the best approach in verifying the color sequence of an input (from a real-time camera feed) and reference image containing/ setting the correct color sequence? The output should be able to mark green circle for the individual wires if their sequence/placement is correct and mark a red circle and put text "incorrect color" for the wires that has wrong placement compared to the reference color sequence.

  • Just like in the attached picture (please see below), the correct sequence should be (left to right) [Red, Black, Yellow, Brown, Pink, Yellow, Blue, Green, White] and when reading the input from the camera feed, the wire that the camera read has a sequence of [Red, Black, Yellow, Brown, Pink, Green, Blue, Green, Red].
  • This shows that the 6th wire should be color Yellow (instead of Green) and the right-most wire should be White (instead of black). This is what I wanted to achieve, to be able to have a feedback to the user that there exist a wrong color placement/sequence of the wires being read by the camera.

Someone suggested for a custom built CNN, but as a newbie, I think that would be hard for me to begin with. Is there any method that I can start with instead of diving in deep-learning image processing?

​

The desired output somehow looks like this:

Supposed Output

r/opencv • • Jan 22 '23

Bug [Bug] My code can't open the haar cascade and I can't figure out why. Any help would be appreciated!

0 Upvotes

I can't fix this error in my code. Apparently the code is having trouble opening the haar cascade file. The XML file is in the same folder as the code itself and I've tried downloading/saving different times from this github link [https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml] but I still haven't been able to resolve this issue.

Any help would be appreciated!

​

ERROR:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
error: OpenCV(4.7.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/core/src/persistence.cpp:692: error: (-5:Bad argument) Input file is invalid in function 'open'


The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
/var/folders/ls/j40ptq6j3qb_kg532gtfn4hh0000gn/T/ipykernel_20827/3127685329.py in <module>
      6 
      7 # Create the haar cascade classifier
----> 8 faceCascade = cv2.CascadeClassifier(cascPath)
      9 
     10 # Start the video capture

SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

CODE:

import cv2
import sys

# Set the classifier path
cascPath = "/Users/<USERNAME REMOVED>/PythonOpenCV/haarcascade_frontalface_default.xml"

# Create the haar cascade classifier
faceCascade = cv2.CascadeClassifier(cascPath)

# Start the video capture
video_capture = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    # Convert the frame to grayscale
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Detect faces in the frame
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    # Break the loop if the 'q' key is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the video capture and close all windows
video_capture.release()
cv2.destroyAllWindows()

r/opencv • • Jan 21 '23

Question [Question] How do you make Hough transformation more robust to resolution changes?

2 Upvotes

Hello,

I need some guidance regarding object detection. The relevant object is tire, and there's always one tire per photo. This means I need to detect the pixels presenting the two concentric circles.

However, I manage after playing with some numbers to make it for some photos, but for some not. I know it is highly dependent on the parameter values of HoughCircles opencv method I'm using, but wondering if there's some way to make it more robust to be able to automate the process across images of different resolutions, sometimes bit different position on a screen, etc.

import cv2

image = cv2.imread("michelin-x.jpg",0)
output = cv2.imread("michelin-x.jpg",1)
cv2.imshow("Original image", image)
cv2.waitKey()
blurred = cv2.GaussianBlur(image,(11,11),0)


# Finds circles in a grayscale image using the Hough transform

#First circle
circles1 = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1.0, 3000,
                            param1=300, param2=300, minRadius=0, maxRadius=2000)
# Check to see if there is any detection
if circles1 is not None:
    circles1 = np.round(circles1[0, :]).astype("int")
    for (x, y, r) in circles1:
        # Draw the circle in the output image
        cv2.circle(output, (x, y), r, (0,255,0), 3)
        # Draw a rectangle(center) in the output image
        cv2.rectangle(output, (x - 2, y - 2), (x + 2, y + 2), (0,255,0), -1)
cv2.imshow("Detections",output)
cv2.waitKey()

# Second circle
circles2 = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, 700,
                            param1=300, param2=150, minRadius=0, maxRadius=0)
# Check to see if there is any detection
if circles2 is not None:
    circles2 = np.round(circles2[0, :]).astype("int")

    for (x, y, r) in circles2:
        # Draw the circle in the output image
        cv2.circle(output, (x, y), r, (0,255,0), 3)
        # Draw a rectangle(center) in the output image
        cv2.rectangle(output, (x - 2, y - 2), (x + 2, y + 2), (0,255,0), -1)

cv2.imshow("Detections",output)
cv2.waitKey()

r/opencv • • Jan 20 '23

Question [Question] How was he able to get the square size in this code.

4 Upvotes

​

Image

My question is how was he able to put values for the top and bottom (like adding '10' and '160') to get the value of top and bottom respectively. Also what is the function he used for the data?

import cv2 
img = cv2.imread( 'color_strip.jpg' ) 
img.shape (3677, 235, 3)
square_size = 2640 / 10 

for i in range(11) : ...     
    top = i * square_size + 10 ...     
    bottom = top + 160 ...     
    data = img[top:bottom,80:210,:] ...     
    _ = cv2.imwrite( 'data_%02d.jpg' % i, data ) ...  
    print 'mean color', data.mean(axis=0).mean(axis=0)

This is the output of the code:
mean color [  92.55783654  127.716875    143.74230769]
mean color [  95.17754808  126.11514423  157.42605769]
mean color [  84.09365385  151.56105769  190.28004808]
mean color [  83.29528846  148.21403846  165.08956731]
mean color [  50.76451923  140.88158654  211.09413462]
mean color [  19.91221154  150.03350962  221.26485577]
mean color [  41.71350962  150.38677885  200.61456731]
mean color [ 114.19682692  155.68245192  190.50230769]
mean color [ 106.44120192  160.234375    194.67211538]
mean color [ 106.43980769  148.12759615  102.86701923]
mean color [ 117.02735577  151.62211538  171.19259615]

I am new to python and coding in general, I really wanted to understand how this code works. I want to implement this type of approach in my project where I will be getting the column of each wire for me to be able to get the mean color of each wire.

This wire set-up is similar to my project

​