Ask Your Question
0

Shape detection using opencv and java

asked 2017-11-08 00:54:29 -0600

ChukZ gravatar image

updated 2017-11-09 07:59:23 -0600

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

  // get the camera frame as gray scale image
  Mat gray = null;

  if (DETECT_RED_OBJECTS_ONLY)
  {
   gray = inputFrame.rgba();
  } 
  else 
  {
   gray = inputFrame.gray();
  }


  // the image to output on the screen in the end
  // -> get the unchanged color image
  Mat dst = inputFrame.rgba();

Here code is used ----org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; But i want to do something like this.I want to convert this android code to opencv java

 public static Mat onCameraFrame(Mat inputFrame) {

    Mat gray = null;
if (DETECT_RED_OBJECTS_ONLY) {
    gray = inputFrame.rgba();
} else {
    gray = inputFrame.gray();
}


// the image to output on the screen in the end
// -> get the unchanged color image
Mat dst = inputFrame.rgba();

now there is no such a thing rgba() & gray().

Please anyone help me to solve this

edit retag flag offensive close merge delete

Comments

Hey buddy. I can guarantee you you'll have a hard time getting someone to actually help you with the current status of your question. You literally just dumped all of your code here and said, here guys fix this. 1: Look at your own code and extract the part that deals with your problem. 2: Provide more details to your question. e.g. What is the current output of your program? What is your desired output? Does it fail? If yes, where? My point is, you need to do work and make it easier for us to help you. Dumping entire programs and expecting us to not only answer your question but also do the heavy lifting as well, normally leads to closed questions. Consider reading this as well to have a better grasp of how to ask questions

eshirima gravatar imageeshirima ( 2017-11-08 08:04:34 -0600 )edit

And what exactly do you mean by Could anyone please help me to build this code. Don't you have a compiler?

eshirima gravatar imageeshirima ( 2017-11-08 08:07:37 -0600 )edit

@eshirima OK understood. Now I have edited my question.

ChukZ gravatar imageChukZ ( 2017-11-08 22:00:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-09 08:22:50 -0600

This is the part where I would recommend you look at their CameraBridgeViewBase.CvCameraViewFrame documentation.

From it, you can see that rgba() and gray() are member functions of the class CvCameraViewFrame. All that they do is return either a coloured or grey frame respectively.

To achieve the same thing in Java, if you look at their documentation they do have a function called cvtColor inside Imgproc defined as

public static void cvtColor(Mat src,
                            Mat dst,
                            int code)

The first two parameters are self explanatory but for the third one, refer to their constant values list and anything with prefix COLOR_ can be passed as an argument. I'll leave it to you to figure out the one that corresponds to what you want.

Recommendation:

Always refer to the documentation if things do not make sense. Now I understand that Java's documentation isn't the greatest in contrast to C++ and Python's. This is were I'd refer you to this answer which should help you better understand the stuff.

edit flag offensive delete link more

Comments

Mat gray = null; if (DETECT_RED_OBJECTS_ONLY) { Imgproc.cvtColor(inputFrame, gray, Imgproc.COLOR_BGR2RGB); } else { Imgproc.cvtColor(inputFrame, gray, Imgproc.COLOR_BGR2GRAY); } Mat dst = null; Imgproc.cvtColor(inputFrame, dst, Imgproc.COLOR_BGR2RGB);

@eshirima here There is an error . Exception in thread "main" java.lang.NullPointerException in first Convert color. input frame has a value but gray is going to be null. I think I didn't understand it correctly.Can you guide me further.

ChukZ gravatar imageChukZ ( 2017-11-12 22:43:59 -0600 )edit

Buddy, documentation is your friend! Coding conventions are different. Stop trying to directly apply one code convention onto the other. Understand the logic then re-write it in the other convention. All that you want is to create an empty frame. This can be done as Mat grey = new Mat(). Look at the Mat() class in their documentation. Please don't forget to up-vote and mark my response as an answer if it helped resolve your problem. This way the question can be marked as closed.

eshirima gravatar imageeshirima ( 2017-11-13 08:08:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-08 00:54:29 -0600

Seen: 1,351 times

Last updated: Nov 09 '17