add toggle button for blueish cam fix (Force OpenCV2 BGR2RGB)
This commit is contained in:
1 parent
79c6615a68
commit
c91ab8bbd2
5 files changed
+24
-8
No files matched your search
@@ -2,6 +2,7 @@ import numpy
|
||||
import opennsfw2
|
||||
from PIL import Image
|
||||
import cv2 # Add OpenCV import
|
||||
import modules.globals # Import globals to access the color correction toggle
|
||||
|
||||
from modules.typing import Frame
|
||||
|
||||
@@ -11,12 +12,16 @@ MAX_PROBABILITY = 0.85
|
||||
model = None
|
||||
|
||||
def predict_frame(target_frame: Frame) -> bool:
|
||||
# Convert the frame to RGB before processing
|
||||
target_frame = cv2.cvtColor(target_frame, cv2.COLOR_BGR2RGB)
|
||||
# Convert the frame to RGB before processing if color correction is enabled
|
||||
if modules.globals.color_correction:
|
||||
target_frame = cv2.cvtColor(target_frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
image = Image.fromarray(target_frame)
|
||||
image = opennsfw2.preprocess_image(image, opennsfw2.Preprocessing.YAHOO)
|
||||
global model
|
||||
if model is None: model = opennsfw2.make_open_nsfw_model()
|
||||
if model is None:
|
||||
model = opennsfw2.make_open_nsfw_model()
|
||||
|
||||
views = numpy.expand_dims(image, axis=0)
|
||||
_, probability = model.predict(views)[0]
|
||||
return probability > MAX_PROBABILITY
|
||||
|
||||
Reference in new issue
Block a user