Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)update:(SolarMasksCameraParameters *)pParametersArg {
- self.pCameraParameters = pParametersArg;
- [self initMaskMatrix];
- //original
- NSString *pictureOriginalPath = [pParametersArg.pictureOriginalUrl path];
- std::string srcOriginal = [self convertToCPPString:pictureOriginalPath];
- //subsample
- NSString *pictureSubsampledPath = [pParametersArg.pictureSubsampledUrl path];
- std::string srcSubsampled = [self convertToCPPString:pictureSubsampledPath];
- //on converti la picture source en matrix
- cv::Mat matSRC = cv::imdecode(
- cv::Mat(1,
- (int) [[pParametersArg picture] length],
- CV_32F,
- (void *) [pParametersArg picture].bytes
- ),
- cv::IMREAD_COLOR
- );
- //on retire une bordure de 30 pixel tout autour pour le pblm de l'iPhone 8
- cv::Mat M_subsampled = matSRC.colRange(30, matSRC.cols - 30).rowRange(30, matSRC.rows - 30).clone();
- //on enregistre l'image originale croppée
- cv::imwrite(srcOriginal, M_subsampled);
- //on susample l'image
- M_subsampled.convertTo(M_subsampled, CV_32F);
- M_subsampled = skydetect::subsample_img(M_subsampled, 256, 0);
- cv::imwrite(srcSubsampled, M_subsampled);
- //Execute algo
- cv::Mat M_algo3 = skydetect::skydetect_algo3(srcOriginal);
- NSString *pictureSDPath = [pParametersArg.pictureSDUrl path];
- std::string srcSD = [self convertToCPPString:pictureSDPath];
- mSDMatrix = M_algo3.colRange(1, M_algo3.cols).rowRange(1, M_algo3.rows - 10).clone();
- cv::imwrite(srcSD, mSDMatrix);
- //Extend mask picture to unknow areas, and write SDEMatrix as a .jpg file
- [self extendMaskPicture];
- NSString *pictureSDEPath = [pParametersArg.pictureSDEUrl path];
- std::string srcSDE = [self convertToCPPString:pictureSDEPath];
- cv::imwrite(srcSDE, mSDEMatrix);
- //Add sky detection matrix to mask matrix
- [self addSkyDetectionMatrixToMaskMatrix];
- //Save mask matrix as a .jpg file
- const int iRows = (int) [mMaskMatrix count];
- const int iColumns = (int) [[mMaskMatrix objectAtIndex:0] count];
- cv::Mat img = cv::Mat(iRows, iColumns, CV_32F);
- for (int iColumn = 0; iColumn < iColumns; ++iColumn) {
- for (int iRow = 0; iRow < iRows; ++iRow) {
- cv::Point point(iColumn, iRow);
- NSNumber *ok = [[mMaskMatrix objectAtIndex:iRow] objectAtIndex:iColumn];
- if (![ok boolValue]) {
- cv::circle(img, point, 1, cv::Scalar(0, 0, 0), 1, 8, 0);
- } else {
- cv::circle(img, point, 1, cv::Scalar(255, 255, 255), 1, 8, 0);
- }
- }
- }
- NSString *pictureMaskMatrixPath = [pParametersArg.pictureMaskMatrixUrl path];
- std::string srcMaskMatrix = [self convertToCPPString:pictureMaskMatrixPath];
- cv::imwrite(srcMaskMatrix, img);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement