Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Please mark my answer as correct, and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Please mark my answer as correct, correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Please mark my answer as correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Thanks to Lberger for this simpler OpenCV code:

ycrcb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YCrCb)

Please mark my answer as correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Thanks to Lberger for this simpler OpenCV code:

ycrcb_frame = cv2.cvtColor(frame, cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2YCrCb)

Please mark my answer as correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Thanks to Lberger LBerger for this simpler OpenCV code:

ycrcb_frame = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2YCrCb)

Please mark my answer as correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Thanks to LBerger for this simpler OpenCV code:

ycrcb_frame = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2YCrCb)

... this is not to say that OpenCV uses the same constants as used here in the manual approach.

Please mark my answer as correct (click the check mark), and please make sure to give me an upvote. :)

image description

import cv2
import numpy

frame = cv2.imread('sparks.png')

if frame is None:
    print('Error loading image')
    exit()

rows = frame.shape[0]
cols = frame.shape[1]

for i in range(0, rows):
    for j in range(0, cols):
        R = frame[i, j][2]
        G = frame[i, j][1]
        B = frame[i, j][0]

        Y =   16 +  65.738*R/256 + 129.057*G/256 +  25.064*B/256
        Cb = 128 -  37.945*R/256 -  74.494*G/256 + 112.439*B/256
        Cr = 128 + 112.439*R/256 -  94.154*G/256 -  18.285*B/256

Thanks to LBerger for this simpler OpenCV code:

ycrcb_frame = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2YCrCb)

... this is not to say that OpenCV uses the same constants as used here in the manual approach.

approach. I think it's a matter of looking into the OpenCV source code.