Ask Your Question

SCBEAR's profile - activity

2020-11-18 04:49:19 -0600 received badge  Popular Question (source)
2015-10-18 22:14:50 -0600 asked a question Hough Circles detection performance

For the function of HoughCircles I have my code written this way

//Debugging purpose
        cout << "2" << endl;

        //Apply HoughCircle function

        HoughCircles(src_gray2, circles, CV_HOUGH_GRADIENT,
        2,   // accumulator resolution (size of the image / 2)
        5,  // minimum distance between two circles
        dparam1, // Canny high threshold
        dparam2, // minimum number of votes
        minR, maxR); // min and max radius

        //Debugging purpose
        cout << "3" << endl;

The dparam1 dparam2 minR and MaxR are slider bars. After this code, is the standard way of drawing the circle on the ROI.

When running the code, the code always stops between 2 and 3. Also i limited the number of circles being drawn to 5 to prevent overloading.

Now the problem is that the code is slow and hang because of this part. So is there a way to speed up this thing, or limit the number of circles being DETECTED? I only have one circle to detect at a time.

NOTE: The dparam1 and 2 are set to around 160 minR and max R are set to 0 as size of circles are unknown.

Thank you

2015-10-14 03:36:24 -0600 asked a question OPENCV Hough circle

I have problem with the houghcircles function, regarding its processing speed. when i try to run the code with this video file, i uploaded onto Youtube. https://youtu.be/5RGRTPEdHVY

The problem is, when the copter is taking off, the code is stucked, and stop moving. At this stage, when the copter is taking off, the param must be set manually at 300 to avoid being stucked. then after taking off, the param must be reduced to about 150 or 130 to detect the circles on the field.

Now i do not want to do it manually, is there a way to do it intelligently?

Or is there any way to ensure the video is smooth?

Thank you

Code is attached.

#include <sstream>
#include <string>
#include <iostream>
#include <vector>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdlib.h>
#include <stdio.h>
#include <opencv2\opencv.hpp>
#include <time.h>
#include <fstream>

#include <stdio.h>
#include <conio.h>
#include "tserial.h"
#include "bot_control.h"


using namespace std;
using namespace cv;


int main(int argc, char** argv) {


    //Create a window for trackbars
    namedWindow("Trackbar Window", CV_WINDOW_AUTOSIZE);

    //Create trackbar to change brightness
    int iSliderValue1 = 50;
    createTrackbar("Brightness", "Trackbar Window", &iSliderValue1, 100);

    //Create trackbar to change contrast
    int iSliderValue2 = 50;
    createTrackbar("Contrast", "Trackbar Window", &iSliderValue2, 100);

    //Create trackbar to change param1 in HoughCircle
    int param1 = 300;
    createTrackbar("param1", "Trackbar Window", &param1, 300);

    //Create trackbar to change param2 in HoughCircle
    int param2 = 300;
    createTrackbar("param2", "Trackbar Window", &param2, 300);

    //Create trackbar to change min Radius in HoughCircle
    int minR = 0;
    createTrackbar("minRadius", "Trackbar Window", &minR, 300);

    //Create trackbar to change max Radius in HoughCircle
    int maxR = 0;
    createTrackbar("maxRadius", "Trackbar Window", &maxR, 300);

    //Debugging purpose
    cout << "All trackbars created" << endl;

    int iBrightness;
    double dContrast;

    double dparam1;
    double dparam2;

    time_t start, end;
    int counter = 0;

    ofstream myfile;

    serial comm;
    char data = 1;

    comm.startDevice("COM3", 9600);

    time(&start);   
    //Create a variable to store image
    Mat src;
    //Create video capture
    VideoCapture capture;
    //open video from either a file or webcam

    capture.open("C:\\Users\\Student-ID\\Downloads\\GOPR0506.MP4");
    //capture.open(0);



    //set frame height
    //capture.set(CV_CAP_PROP_FRAME_HEIGHT, 120);
    //capture.set(CV_CAP_PROP_FRAME_WIDTH, 120);

    //Set the capture FPS
    //capture.set(CV_CAP_PROP_FPS,25);

    //store whatever is captured to src
    capture.read(src);

    //Debugging purpose
    cout << "Vidoe opened" << endl;

    if (!src.data) {
        std::cout << "ERROR:\topening image" << std::endl;
        return -1;
    }

    //Create window to display videos
    cv::namedWindow("image1", CV_WINDOW_AUTOSIZE);

    vector<Vec3f> circles;
    while (true){

        capture.read(src);
        //Code for changing Brightness and contrast
        iBrightness = iSliderValue1 - 50;
        dContrast = iSliderValue2 / 50.0;
        src.convertTo(src, -1, dContrast, iBrightness);

        //Debugging purpose
        //cout << "1" << endl;


        //Create variable to store the processed image
        Mat src_gray2;
        //Convert the colour to grayscale
        cvtColor(src, src_gray2, CV_BGR2GRAY);
        //Smooth and blur the image to reduce noise
        GaussianBlur(src_gray2, src_gray2, cv::Size(9, 9), 2, 2);





        //Change the param1 and 2 to double from integer
        dparam1 = param1 / 1.0;
        dparam2 = param2 / 1.0;

        //Debugging purpose
        cout << "2" << endl;

        //Apply ...
(more)
2015-10-03 01:52:13 -0600 asked a question Livefeed video is not moving

I am using the TS351 and RC305 Vtx set with EasyCap capture card to transmit the video i captured back to the computer for processing. However the video in the video window always stop after some time. image description

So halfway doing the livefeed, the screen just stuck there and it is not moving anymore. It may work after i re-launch my program. I wonder what is actually the problem, the easycap does not seem to be lagging as seen from the Honestech TVR software. The Vtx set was working fine before.

Is my code too long and heavy, that the while loop is unable to process that fast? or is there other problems?

my code is attached. It is damn long... ya.. it is to detect a specified colour and is working fine with video files

I am using OPENCV 3.0.0 C++ on Windows 8 64 bit system, on Microsoft Visual Studio 2013

//objectTrackingTutorial.cpp

//Written by  Kyle Hounslow 2013

//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")
//, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
//IN THE SOFTWARE.

#include <sstream>
#include <string>
#include <iostream>
#include <vector>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdlib.h>
#include <stdio.h>

using namespace cv;
using namespace std;
//initial min and max HSV filter values.
//these will be changed using trackbars

int H_MIN = 0;
int H_MAX = 256;
int S_MIN = 0;
int S_MAX = 256;
int V_MIN = 0;
int V_MAX = 256; //original*/



//default capture width and height
const int FRAME_WIDTH = 640;
const int FRAME_HEIGHT = 480;
//max number of objects to be detected in frame
const int MAX_NUM_OBJECTS=50;
//minimum and maximum object area
const int MIN_OBJECT_AREA = 20*20;
const int MAX_OBJECT_AREA = FRAME_HEIGHT*FRAME_WIDTH/1.5;
//names that will appear at the top of each window
const string windowName = "Original Image";
const string windowName1 = "HSV Image";
const string windowName2 = "Thresholded Image";
const string windowName3 = "After Morphological Operations";
const string trackbarWindowName = "Trackbars";

//Declare variable for Brightness and Contrast control
int iSliderValue1 = 50;
int iSliderValue2 = 50;

void B_C(){
    //Create a window
    namedWindow("Brightness & Contrast", CV_WINDOW_AUTOSIZE);

    //Create trackbar for Brightness
    createTrackbar("Brightness ...
(more)
2015-10-03 01:22:06 -0600 asked a question GOPro Wifi compatibility with opencv 3.0.0

I heard from many sources that OPENCV does not work well with video live feed. However, I came across this link https://gist.github.com/GOROman/6248503

cv::VideoCapture cap( "http://10.5.5.9:8080/live/amba.m3u8" );

This is the WIFI address for GOPRO hero 3. (I believe it is, but not sure as i never use wifi cam before).

Can this code open up the video livefeed for GOpro? And the video can be processed like to detect colours and shapes? Because i am working on off-board live video processing, dealing with intermittent signals of TS351 and RC305. And Easycap video capture card is quite slow....

I am using OPENCV 3.0.0 C++ on Microsoft Visual Studio 2013, running Win 8 64bit system.

2015-09-25 01:46:49 -0600 asked a question arduino and opencv visual studio

I have an opencv code running on Ms Visual Studio 2013, the code is on colour detection (eg red colour). SO once red colour is detected on a camera connected, the code will output to a txt file using the iostream library like this

o

fstream myfile;
myfile.open("C:\\Users\\Student - ID\\Downloads\\SPACe Mission         IIIA\\CVbook\\CV colour Communication\\CV colour Communication\\XX.txt");
myfile << "1";
myfile.close();

And from here, i will send out the number 1 to show red colour is detected. or if it is not detected, it will send out 0.

And here, my arduino is connected to an Xbee, I wish there is something that can read the txt file and load the number to the arduino. Is it possible?

My ultimate goal is to get a digital signal from Visual Studio that can be understood by arduino and transmit out via Xbee

Or if you have any other better ways, do you mind sharing with me? Thank you very much

2015-09-23 00:13:11 -0600 received badge  Enthusiast
2015-09-20 03:13:22 -0600 received badge  Editor (source)
2015-09-20 03:12:28 -0600 commented question Hough Circle with trackbars

Thank you Is it normal to experience lags when detecting circle through the laptop built-in webcam? I used param 1 and 2 = 100 and 150 +- and i experience lags of about 3 seconds. is there a way to reduce such lag? the circle i am detecting is of different radius, i kept both min and max to zero anyway. updated the code above

2015-09-20 02:33:24 -0600 commented question Hough Circle with trackbars

Hi Thank you very very much for your reply Is there anywhere explain how different values of param1 and 2 will affect the number of circles?

Min max radius yes, was only trying on param1 and 2.. but somewhere on the internet, it says if the radius is unknown, put both as 0?

Thank you again

2015-09-20 00:06:30 -0600 asked a question Hough Circle with trackbars

There are a few parameters in the HoughCirclefunction. Is there a way to use the trackbars to change these parameters? so that I would not need to run the program every time i want to change them.

Thank you.

using opencv 3.0.0 C++ on Ms VS 2013 on Win 8 laptop

#include <sstream>
#include <string>
#include <iostream>
#include <vector>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using namespace cv;


int main(int argc, char** argv) {

    //Create a window for trackbars
    namedWindow("Trackbar Window", CV_WINDOW_AUTOSIZE);

    //Create trackbar to change brightness
    int iSliderValue1 = 50;
    createTrackbar("Brightness", "Trackbar Window", &iSliderValue1, 100);

    //Create trackbar to change contrast
    int iSliderValue2 = 50;
    createTrackbar("Contrast", "Trackbar Window", &iSliderValue2, 100);

    int param1 = 100;
    createTrackbar("param1", "Trackbar Window", &param1, 300);

    int param2 = 200;
    createTrackbar("param2", "Trackbar Window", &param2, 300);

    int minR = 0;
    createTrackbar("minRadius", "Trackbar Window", &minR, 300);

    int maxR = 0;
    createTrackbar("maxRadius", "Trackbar Window", &maxR, 300);


    cout << "All trackbars created" << endl;


    Mat src;

    VideoCapture capture;

    //capture.open("GOPR0496.MP4");
    capture.open(0);
    capture.read(src);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);

    cout << "Vidoe opened" << endl;

    if (!src.data) {
        std::cout << "ERROR:\topening image" << std::endl;
        return -1;
    }
    cv::namedWindow("image1", CV_WINDOW_AUTOSIZE);

    cv::namedWindow("image2", CV_WINDOW_AUTOSIZE);

    while (true){

        capture.read(src);

        int iBrightness = iSliderValue1 - 50;
        double dContrast = iSliderValue2 / 50.0;
        src.convertTo(src, -1, dContrast, iBrightness);
        cout << "1" << endl;

        cv::imshow("image1", src);

    Mat src_gray2;
    cvtColor(src, src_gray2, CV_BGR2GRAY);

    GaussianBlur(src_gray2, src_gray2, cv::Size(9, 9), 2, 2);

    vector<Vec3f> circles;
    cout << "2" << endl;

    double dparam1 = param1 / 1.0;
    double dparam2 = param2 / 1.0;
    HoughCircles(src_gray2, circles, CV_HOUGH_GRADIENT,
        2,   // accumulator resolution (size of the image / 2)
        5,  // minimum distance between two circles
        dparam1, // Canny high threshold
        dparam2, // minimum number of votes
        minR, maxR); // min and max radius
    cout << "3" << endl;

    std::cout << circles.size() << std::endl;
    std::cout << "end of test" << std::endl;


    for (size_t i = 0; i < circles.size(); i++)
    {
        Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
        circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);
        // circle outline
        circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);
        putText(src, "Circle Found", Point(0, 50), 1,2,Scalar(0, 255, 0),2);
    }

    /*std::vector<cv::Vec3f>::
        const_iterator itc = circles.begin();

    while (itc != circles.end()) {

        cv::circle(src_gray2,
            cv::Point((*itc)[0], (*itc)[1]), // circle centre
            (*itc)[2],       // circle radius
            cv::Scalar(0,0,0), // color
            2);              // thickness

        ++itc;
    }*/

    cv::imshow("image2", src_gray2);
    imshow("image1", src);
    cout << "5" << endl;
    cvWaitKey(33);
    }
    return 0;
}

I have the cout expression to help me with locating the bug. In the window, it is showing like this enter image description here CMD window

And there is a problem with the HoughCircle function.

The code stops at number 2, and after like 10 seconds, it jump to 3 and loop over. I can't see what is the problem. The ... (more)

2015-09-12 22:49:56 -0600 asked a question opencv camera capture issues

I am using Opencv 3.0.0 ver on a Windows 7 computer.

So I have my videos transmitted back using the TS351 and RC305 set, and captured by the Easycap USB 2.0. However, the easycap is causing lags.

I wish to know if there is other devices that are faster and perform the same function?

And what if I use the RCA to USB cable, will it serve the same purpose?

2015-08-11 10:38:20 -0600 asked a question Open Gopro hero wifi live streaming with VS C++

I saw some tutorials that they can open a Gopro hero wifi livefeed by its url with Videocapture function. Is it possible?

if can open, is there any sample video tutorials for my reference? if cannot open, i think i have no choice but to use the analog transmission to transmit the video back to the computer.

Is gopro hero a good device to use for live streaming?

thank you