gpt4 book ai didi

iphone - 如何将黑色变为白色

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:18 24 4
gpt4 key购买 nike

enter image description here使用以下代码,将上面显示的图像转换为下面的图像...它们显示带有灰色线条的黑色背景.....我想要带有灰色线条的白色背景..请指导我..我是 iPhone 的新手提前致谢

- (void)viewDidLoad
{
[super viewDidLoad];

// Initialise video capture - only supported on iOS device NOT simulator
#if TARGET_IPHONE_SIMULATOR
NSLog(@"Video capture is not supported in the simulator");
#else
_videoCapture = new cv::VideoCapture;
if (!_videoCapture->open(CV_CAP_AVFOUNDATION))
{
NSLog(@"Failed to open video camera");
}
#endif

// Load a test image and demonstrate conversion between UIImage and cv::Mat
UIImage *testImage = [UIImage imageNamed:@"testimage.jpg"];

double t;
int times = 10;

//--------------------------------
// Convert from UIImage to cv::Mat
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

t = (double)cv::getTickCount();

for (int i = 0; i < times; i++)
{
cv::Mat tempMat = [testImage CVMat];
}

t = 1000 * ((double)cv::getTickCount() - t) / cv::getTickFrequency() / times;

[pool release];

NSLog(@"UIImage to cv::Mat: %gms", t);

//------------------------------------------
// Convert from UIImage to grayscale cv::Mat
pool = [[NSAutoreleasePool alloc] init];

t = (double)cv::getTickCount();

for (int i = 0; i < times; i++)
{
cv::Mat tempMat = [testImage CVGrayscaleMat];
}

t = 1000 * ((double)cv::getTickCount() - t) / cv::getTickFrequency() / times;

[pool release];

NSLog(@"UIImage to grayscale cv::Mat: %gms", t);

//--------------------------------
// Convert from cv::Mat to UIImage
cv::Mat testMat = [testImage CVMat];

t = (double)cv::getTickCount();

for (int i = 0; i < times; i++)
{
UIImage *tempImage = [[UIImage alloc] initWithCVMat:testMat];
[tempImage release];
}

t = 1000 * ((double)cv::getTickCount() - t) / cv::getTickFrequency() / times;

NSLog(@"cv::Mat to UIImage: %gms", t);

// Process test image and force update of UI
_lastFrame = testMat;
[self sliderChanged:nil];
}
- (IBAction)capture:(id)sender
{
if (_videoCapture && _videoCapture->grab())
{
(*_videoCapture) >> _lastFrame;
[self processFrame];
}
else
{
NSLog(@"Failed to grab frame");
}
}
- (void)processFrame
{
double t = (double)cv::getTickCount();

cv::Mat grayFrame, output;

// Convert captured frame to grayscale
cv::cvtColor(_lastFrame, grayFrame, cv::COLOR_RGB2GRAY);

// Perform Canny edge detection using slide values for thresholds
cv::Canny(grayFrame, output,
_lowSlider.value * kCannyAperture * kCannyAperture,
_highSlider.value * kCannyAperture * kCannyAperture,
kCannyAperture);

t = 1000 * ((double)cv::getTickCount() - t) / cv::getTickFrequency();

// Display result
self.imageView.image = [UIImage imageWithCVMat:output];
self.elapsedTimeLabel.text = [NSString stringWithFormat:@"%.1fms", t];
}

enter image description here

最佳答案

反转灰度 1 channel Mat 是:

Mat invertedOutput = 255 - output;

关于iphone - 如何将黑色变为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12889642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com