title: Android CameraX | Color detection
body: <p>I'm working with the new CameraX on Android.</p>
  
  <p>I did a basic application (similar to the "Get Started") in which I have a camera preview and a luminosity analyzer. Every second I display my lumonisity in a TextView.</p>
  
  <p>Now, following the CameraX guidelines, I would like to do color detection. Every second or so, I want to have the color from the pixel in the center of my screen.</p>
  
  <p>The fact is that I don't know how to do color detection following the same sructure as luminosity analyzer.</p>
  
  <p><strong>Luminosity Analyzer Class :</strong> </p>
  
  <pre><code>class LuminosityAnalyzer : ImageAnalysis.Analyzer {
  
  private var lastTimeStamp = 0L
  private val TAG = this.javaClass.simpleName
  var luma = BehaviorSubject.create&lt;Double&gt;()
  
  override fun analyze(image: ImageProxy, rotationDegrees: Int) {
      val currentTimeStamp = System.currentTimeMillis()
      val intervalInSeconds = TimeUnit.SECONDS.toMillis(1)
      val deltaTime = currentTimeStamp - lastTimeStamp
      if(deltaTime &gt;= intervalInSeconds) {
          val buffer = image.planes[0].buffer
          val data = buffer.toByteArray()
          val pixels = data.map { it.toInt() and 0xFF }
          luma.onNext(pixels.average())
          lastTimeStamp = currentTimeStamp
          Log.d(TAG, "Average luminosity: ${luma.value}")
      }
  
  
  private fun ByteBuffer.toByteArray(): ByteArray {
      rewind()
      val data = ByteArray(remaining())
      get(data)
      return data
  }
  }
  </code></pre>
  
  <p><strong>Main Activity :</strong></p>
  
  <pre><code>/* display the luminosity */
  private fun createLuminosityAnalyzer(): ImageAnalysis{
      val analyzerConfig = ImageAnalysisConfig.Builder().apply {
          setLensFacing(lensFacing)
          setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
      }.build()
  
      val analyzer = ImageAnalysis(analyzerConfig).apply {
          val luminosityAnalyzer = LuminosityAnalyzer()
          luminosityAnalyzer.luma
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe({
              // success
              luminosity.text = it.toString()
          },{
              // error
              Log.d(TAG, "Can not get luminosity :(")
          })
          setAnalyzer(executor, luminosityAnalyzer)
      }
      return analyzer
  }
  </code></pre>
  
  <p><strong>How can I do something equivalent but being a Color Analyzer ?</strong></p>