Ask Your Question

jossyy's profile - activity

2020-08-18 04:57:11 -0600 received badge  Popular Question (source)
2019-04-01 10:44:23 -0600 received badge  Popular Question (source)
2017-09-06 06:58:26 -0600 received badge  Notable Question (source)
2017-06-11 19:57:24 -0600 received badge  Famous Question (source)
2016-11-22 07:27:49 -0600 received badge  Popular Question (source)
2016-05-18 03:15:14 -0600 received badge  Notable Question (source)
2016-03-01 21:45:28 -0600 received badge  Popular Question (source)
2015-03-27 03:25:46 -0600 received badge  Enthusiast
2015-03-24 12:05:57 -0600 received badge  Organizer (source)
2015-03-24 12:05:16 -0600 asked a question Template matching problem on Android

I want to create an android application. Program steps are below.

  1. Open camera
  2. Get frames
  3. Select a frame by touch screen
  4. Load template image under drawable folder
  5. Apply template matching
  6. Show result

The mat object of template image is not empty. I check it. When I run this code, I get below error message. image description

Code :

 public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    temp = new Mat(height, width, CvType.CV_8UC4);
    }
public boolean onTouch(View v, MotionEvent event) {
int cols = mRgba.cols();
int rows = mRgba.rows();

int xOffset = (mOpenCvCameraView.getWidth() - cols) / 2;
int yOffset = (mOpenCvCameraView.getHeight() - rows) / 2;

int x = (int)event.getX() - xOffset;
int y = (int)event.getY() - yOffset;

Log.i(TAG, "Touch image coordinates: (" + x + ", " + y + ")");

if ((x < 0) || (y < 0) || (x > cols) || (y > rows)) return false;

mIsColorSelected = true;
return true; // don't need subsequent touch events
}

private static Mat readInputStreamIntoMat(InputStream inputStream) throws IOException {
// Read into byte-array
byte[] temporaryImageInMemory = readStream(inputStream);

// Decode into mat. Use any IMREAD_ option that describes your image appropriately
Mat outputImage = Highgui.imdecode(new MatOfByte(temporaryImageInMemory),        Highgui.IMREAD_GRAYSCALE);

return outputImage;
}

private static byte[] readStream(InputStream stream) throws IOException {
// Copy content of the image to byte-array
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];

while ((nRead = stream.read(data, 0, data.length)) != -1) {
    buffer.write(data, 0, nRead);
}

buffer.flush();
byte[] temporaryImageInMemory = buffer.toByteArray();
buffer.close();
stream.close();
return temporaryImageInMemory;
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

   if(mIsColorSelected) {
   InputStream inpT = getResources().openRawResource(R.drawable.imgt);
   Mat mTemp;
    try {
        mRgba.copyTo(temp);
        mTemp = readInputStreamIntoMat(inpT);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // / Create the result matrix
    int result_cols = temp.cols() - mTemp.cols() + 1;
    int result_rows = temp.rows() - mTemp.rows() + 1;
    Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
    int match_method = 4;
    // / Do the Matching and Normalize
    Imgproc.matchTemplate(temp, mTemp, result, match_method);
      Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
 /*
     Localizing the best match with minMaxLoc
    MinMaxLocResult mmr = Core.minMaxLoc(result);

    Point matchLoc;
    if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
        matchLoc = mmr.minLoc;
    } else {
        matchLoc = mmr.maxLoc;
    }/*
    // / Show me what you got
    Core.rectangle(temp, matchLoc, new Point(matchLoc.x + mTemp.cols(),
            matchLoc.y + mTemp.rows()), new Scalar(0, 255, 0));*/
    return temp;
}
else {
    mRgba = inputFrame.rgba();
}

return mRgba;
}
2015-03-10 03:20:55 -0600 commented answer Load and show image using Opencv on Android Studio

I try this code on emulator. It says same message. "unfortunately, application has stopped"

2015-03-10 03:06:51 -0600 commented question Load and show image using Opencv on Android Studio

I download opencv-android-2.4.9-sdk. Should I use native c++ libs? To use opencv on android, what is the best way?

2015-03-10 02:45:55 -0600 asked a question Load and show image using Opencv on Android Studio

I try to create simple android app that shows an image. I can show the image without opencv.

  1. I copy the image under src/drawable folder.
  2. Content of activity_main.xml file
<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"    tools:context=".MainActivity">
 <ImageView android:src="@drawable/logo"
 android:id="@+id/imageView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />
  </RelativeLayout>
  1. Content of onCreate method in MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   }

But I want to do this work using opencv functions. I use below code in onCreate function. I run the code on virtual device and get unfortunately, application has stopped. What is the wrong on this code?

Code :

// make a mat and draw something
  Mat m = Mat.zeros(100,400, CvType.CV_8UC3);
Core.putText(m, "hello world", new Point(30,80), Core.FONT_HERSHEY_SCRIPT_SIMPLEX, 2.2, new Scalar(200,200,0),2);
// convert to bitmap:
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(m, bm);

// find the imageview and draw it!
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);

My logcat message is here;

 No implementation found for long org.opencv.core.Mat.n_zeros(int, int, int) (tried       Java_org_opencv_core_Mat_n_1zeros and Java_org_opencv_core_Mat_n_1zeros__III)
    at org.opencv.core.Mat.n_zeros(Native Method)
    at org.opencv.core.Mat.zeros(Mat.java:2431)
2014-12-09 14:01:17 -0600 marked best answer opencv create mat object with a loop

Hello,

I use this code :

Mat sampleMat = (Mat_<float>(1,1) << (trainData[i][0]));

But I want to create mat object with a loop. Maybe it looks like this :

Mat sampleMat = (Mat_<float>(1,size) << for(j < size)(trainData[i][j]));

How can I do this?

2014-12-09 13:08:01 -0600 marked best answer random forest predict function returns -1

Hi,

My feature vector's size is 5. The content is filled with 1,0,-1 values... there are two classes. My train data's size is 243 and 16 of them is belong to fist class.The first class labeled with 1, the other is -1.

The predict function returns -1 always

2014-12-06 10:36:52 -0600 asked a question Stereo calibration using findChessboardCorners

I try to calculate 3D position from stereo camera using epipolar line. I want to calibrate my cameras. I use below code, but the findChessboardCorners never returned the true value.What can I do? Is there an logical error in this code?

int board_w = 9;//atoi(argv[2]);
int board_h = 7;//atoi(argv[3]);

Size board_sz = Size(board_w, board_h);
int board_n = board_w*board_h;

vector<vector<Point3f> > object_points;
vector<vector<Point2f> > imagePoints1, imagePoints2;
vector<Point2f> corners1, corners2;

vector<Point3f> obj;
for (int j=0; j<board_n; j++)
{
    obj.push_back(Point3f(j/board_w, j%board_w, 0.0f));
}

Mat img1, img2, gray1, gray2;
VideoCapture cap1 = VideoCapture(1);
VideoCapture cap2 = VideoCapture(2);

cap1.set(CV_CAP_PROP_FRAME_WIDTH, 300);
cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 300);
cap2.set(CV_CAP_PROP_FRAME_WIDTH, 300);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 300);

int k = 0;
bool found1 = false, found2 = false;
bool success = false;
while (!(found1==true && found2==true))
{
    std::cout << "cap frame\n";
    cap1 >> img1;
    cap2 >> img2;

cvtColor(img1, gray1, CV_BGR2GRAY);
cvtColor(img2, gray2, CV_BGR2GRAY);

found1 = findChessboardCorners(img1, board_sz, corners1, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
found2 = findChessboardCorners(img2, board_sz, corners2, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

if (found1)
{
    cornerSubPix(gray1, corners1, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
    drawChessboardCorners(gray1, board_sz, corners1, found1);
    cout << "findChessboardCorners-1\n";
    waitKey(0);
}

if (found2)
{
    cornerSubPix(gray2, corners2, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
    drawChessboardCorners(gray2, board_sz, corners2, found2);
    cout << "findChessboardCorners-2\n";
    waitKey(0);
}

imshow("image1", gray1);
imshow("image2", gray2);
}
2014-10-26 15:30:59 -0600 commented answer pointPolygonTest in OpenCV

thanks @petititi. I close the shape another way, and it works :) thank you again.

2014-10-26 14:46:03 -0600 commented answer pointPolygonTest in OpenCV

I tried it but it didn't work.

2014-10-26 13:59:58 -0600 commented question pointPolygonTest in OpenCV

I used drawContours and there is a result image in my question text. All calculated distance are negative now.

2014-10-26 10:57:22 -0600 asked a question pointPolygonTest in OpenCV

I want to find center of palm. Firstly,I found contours and select max area contour. And I used pointPolygonTest. My code and result image are below, but I didn't find any point using pointPolygonTest. What is the problem?

`

     double dist, maxdist = -1;
     Point center;

    for(int i = 0; i< drawing.cols; i += 10) {
    for(int j = 0; j< drawing.rows; j += 10) {

        dist = pointPolygonTest(contours[maxAreaIndex], Point(i,j),true);
        cout << "   dist " << dist << endl;
        if(dist > maxdist)
        {
            maxdist = dist;
            center = cv::Point(i,j);
        }
    }
}
cout << "maxdist = " << maxdist << endl;
circle(drawing, center, maxdist, cv::Scalar(220,75,20),1,CV_AA);
/// Show in a window
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
imshow( "Contours", drawing );`

The drawing image is below image description

2014-10-26 09:10:37 -0600 commented question How can I find defect points?

@FooBar thanks your help. I use different algorithm for center of palm.

2014-10-26 04:52:06 -0600 commented question How can I find defect points?

I used this function convexityDefects(polyContour, hullInt, defects);

For convex hull, convexHull(contours[maxAreaIndex], hullInt, false);

2014-10-26 04:21:57 -0600 commented question How can I find defect points?

I used convexityDefects() function in opencv. The function gives 4 integer numbers. I used third number. int x = 0,y = 0; for(int i = 0; i < defects.size(); i++) {

    Point p1 = contours[maxAreaIndex].at(defects[i].val[2]);
    x += p1.x;
    y += p1.y;
}

// draw a circle for palm center
circle(drawing, Point(x/defects.size(), y/defects.size()), 3, Scalar( 0, 255, 0 ), 3);

http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#convexitydefects

2014-10-26 03:38:31 -0600 commented question How can I find defect points?

Blue points are defects. I tried to find two points on wrist and four points between fingers. I calculated these 6 points's center.And it would be center of palm.

2014-10-25 16:15:20 -0600 asked a question How can I find defect points?

I want to find hand and palm. I used below algorithm :

1- Get a frame from webcam 2- Convert to grayscale, apply blur and threshold method. 3- Use canny method and findContours 4- Find the contour which has max area, draw it 5- Find and draw convex hull 6- Apply convexityDefects

My result is below :

image description

I wanted to find palm center. For this, I used below code after defects was found.

It calculates average of defects point's coordinate. But the result is not good bacause the defect points aren't found regularly. How can I get better result?

int x = 0,y = 0;
    for(int i = 0; i < defects.size(); i++) {

        Point p1 = contours[maxAreaIndex].at(defects[i].val[2]);
        x += p1.x;
        y += p1.y;
    }

    // draw a circle for palm center
    circle(drawing, Point(x/defects.size(), y/defects.size()), 3, Scalar( 0, 255, 0 ), 3);
2014-09-28 20:35:56 -0600 asked a question videocapture cannot open default camera

I tried to open default camera using below code. But it can't. There is a topic same issue.But I can't find a menu to include HAVE_VIDEOINPUT HAVE_DSHOW. ( I tried cap(0) and cap(1) )

I installed xenomai on ubuntu and compiled kernel. Before it, my code was fine. Maybe default camera was changed. How can I check id of default camera?

image description

2014-06-26 10:37:22 -0600 commented question CvMat can not be resolved

I find a clear example. I learn how I use KNN via this link https://github.com/atduskgreg/kaggle-titanic/blob/master/titanic_knn/KNN.pde

2014-06-26 10:26:30 -0600 asked a question CvMat can not be resolved

Hello, I use eclipse ide on windows for my project. And I want to use opencv with java. I added import org.opencv.*; But I get an error via "CvMat can not be resolved".

CvMat* trainData = cvCreateMat( train_sample_count, 2, CV_32FC1 ); CvMat* trainClasses = cvCreateMat( train_sample_count, 1, CV_32FC1 );

2014-06-23 13:31:40 -0600 commented question Download opencv for java

thank you...

2014-06-22 17:22:26 -0600 asked a question Download opencv for java

Hello, I want to code with java. And I need opencv's methods. I don't clear that what I do. I need a jar file for opencv. Should I downloaded JavaCV? I plan to use eclipse ide.

2014-04-30 07:31:06 -0600 commented question double free or corruption

There is not a problem in these code. I forgot something on other parts of my code.

2014-04-29 18:14:21 -0600 asked a question double free or corruption

Hello,I have a class , and there is a member vector<cvtrees*> vect. I generate many cvtrees object and push on vect. I use this function for train

Mat trainingDataMat(trainSize, featureSize, CV_32FC1); ........ fill trainingDataMat..... for(int i = 0; i < LOOP; i++) { Mat labelMat(trainSize, 1, CV_32FC1); ........... fill labelMat......... // learn classifier CvRTrees rtrees = new CvRTrees(); (rtrees).train( trainingDataMat, CV_ROW_SAMPLE, labelMat, Mat(), Mat(), Mat(), Mat(), CvRTParams()); this->rtreesVector.push_back(rtrees); }

And I use a function for predict. When I run below code, I get an error no source...

Mat testSample(1, featureSize, CV_32FC1); for(int k = 0; k < featureSize; k++) {

          testSample.at<float>(k) = (float)this->trainInvoiceVector[i]->at(j,

k); } for(int i = 0; i < this->rtreesVector.size(); i++) { int response = (int)((*(this->rtreesVector[i])).predict( testSample ));

2014-04-27 07:40:34 -0600 commented answer errors building opencv with visual studio 2013

I am sorry for I am late. I watched a video , I sent it you.. http://www.youtube.com/watch?v=KO6BswerTDM

2014-04-06 17:31:41 -0600 asked a question documentation of random forest

Hello ,

I want to judicious decide parameters of RF constructor. I don't know which the values of them I can select. I use default values. Could you offer me a tutorial for this?

2014-03-20 19:25:00 -0600 commented question opencv2/core/ultility.hpp not found

yes , it is opencv samples. the name is opencv_source_code/samples/ocl/surf_matcher.cpp

2014-03-20 09:08:56 -0600 commented question opencv2/core/ultility.hpp not found

I tried it but there are many error on compile.

2014-03-20 06:54:23 -0600 commented question opencv2/core/ultility.hpp not found

opencv version is 2.3.1

2014-03-20 06:25:53 -0600 asked a question opencv2/core/ultility.hpp not found

Hello,

I have a problem. My compiler says that "fatal error: opencv2/core/utility.hpp: No such file or directory compilation terminated". There isnot the file in my opencv2 folder. What should I do?

I read this title ,but I dont understand the solution. http://answers.opencv.org/question/14755/opencv2coreultilityhpp-not-found/

2014-03-20 06:23:06 -0600 commented answer opencv2/core/ultility.hpp not found

Hello , I have same problem. And I dont understand your solution. There isnot the utility.hpp In my opencv2 folder.