Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get colour of particular pixel from live camera preview - Ionic

I'm trying to recreate functionality which is similar to this: http://tvbarthel.fr/CameraColorPicker/resources/Screenshot_2015-05-17-17-04-27_framed.png using Ionic.

The screenshot demonstrates an inner circle on a live camera preview which grabs the colour along with an outer circle which shows the colour of the pixel currently being looked at.

I have the live camera preview working with overlays however I don't know where to begin with grabbing a colour from a particular spot on the screen.

I understand you can take a photo and grab the colours that way but that isn't the functionality I was after, I was looking at something which allows me to see the results in real-time.

Can this functionality be achieved? If so, how can I do this?

like image 737
nopassport1 Avatar asked Oct 21 '17 14:10

nopassport1


People also ask

How do I add a color to an ionic component?

Then, create a new class that uses these CSS variables. The class must be written in the format .ion-color- {COLOR} where {COLOR} is the name of the color to add: After the class is added, the color can be used on any Ionic component that supports the color property.

How to customise image capturing dialog in ionic app?

If you need more control over the image capturing dialog inside your Ionic app, you need a different plugin since the standard camera plugin doesn’t allow any customisation. In this Quick Win we will use the Capacitor camera-preview plugin to create out own custom overlay above the image capturing dialog.

What is a color in ionic?

Each color is actually a collection of multiple properties, including a shade and tint, used throughout Ionic. A color can be applied to an Ionic component in order to change the default colors using the color attribute. Notice in the buttons below that the text and background changes based on the color set.

How to get the channel and pixel values of an image?

You can use : pixel value = image.at<unsigned char=""> (cv::Point (x,y)) ; channel1_value = image.at<vec3b> (cv::Point (x, y)) [0] ;


1 Answers

Can this functionality be achieved? If so, how can I do this?

I faced similar situation in my Application so thought it will be helpful.

I was creating a Cordova-Angular Hybrid app for real time image processing:

  1. Open the front camera and show the different objects in-front of camera.

  2. If object found in the dictionary then display the success message and stop previewing.

Here were the Steps:

  1. Created new Cordova plugin that start the camera in previewMode. For getting the current image of the preview you need to override the onPreviewFrame method.

  2. Get the buffer the image and convert it and Match it.

  3. Based on success/fail call the callBack Method.

Now I think in your case Step-1 will be same with some additional Steps.

  1. Create new Cordova plugin that will start the camera in previewMode. For getting the current image of the preview you need to override the onPreviewFrame method.

  2. Override the onTouchEvent method to calculate the point inside the ImageView and in same time calculate the pixel of the frame inside onPreviewFrame method.

  3. After getting the result just update the view with result.

Also I think the main part in this ionic app is still native.Cordova will just do the bridging.

References:

  1. http://topandroidphones1.blogspot.com/2012/04/get-color-on-specified-location-from.html

  2. OnPreviewFrame data image to imageView

  3. Get the touch position inside the imageview in android

  4. How to Get Pixel Color in Android

  5. Capturing the Camera Preview with a PreviewCallback

like image 119
NullPointer Avatar answered Oct 03 '22 03:10

NullPointer